@scm-manager/ui-api 2.36.1 → 2.36.2-20220522-120507

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 (79) hide show
  1. package/build/index.d.ts +735 -0
  2. package/build/index.js +3200 -0
  3. package/build/index.mjs +3031 -0
  4. package/package.json +15 -10
  5. package/LICENSE.txt +0 -21
  6. package/src/ApiProvider.test.tsx +0 -60
  7. package/src/ApiProvider.tsx +0 -80
  8. package/src/LegacyContext.test.tsx +0 -52
  9. package/src/LegacyContext.tsx +0 -75
  10. package/src/admin.test.ts +0 -55
  11. package/src/admin.ts +0 -42
  12. package/src/alerts.ts +0 -107
  13. package/src/annotations.ts +0 -45
  14. package/src/apiKeys.ts +0 -82
  15. package/src/apiclient.test.ts +0 -126
  16. package/src/apiclient.ts +0 -336
  17. package/src/base.test.ts +0 -238
  18. package/src/base.ts +0 -120
  19. package/src/branches.test.ts +0 -234
  20. package/src/branches.ts +0 -201
  21. package/src/changesets.test.ts +0 -178
  22. package/src/changesets.ts +0 -82
  23. package/src/compare.ts +0 -90
  24. package/src/config.test.ts +0 -118
  25. package/src/config.ts +0 -60
  26. package/src/configLink.test.ts +0 -169
  27. package/src/configLink.ts +0 -89
  28. package/src/contentType.ts +0 -58
  29. package/src/diff.test.ts +0 -234
  30. package/src/diff.ts +0 -93
  31. package/src/errors.test.ts +0 -59
  32. package/src/errors.ts +0 -133
  33. package/src/fileContent.ts +0 -33
  34. package/src/groupSuggestions.ts +0 -32
  35. package/src/groups.test.ts +0 -241
  36. package/src/groups.ts +0 -141
  37. package/src/help/search/modal.de.ts +0 -33
  38. package/src/help/search/modal.en.ts +0 -33
  39. package/src/help/search/syntax.de.ts +0 -148
  40. package/src/help/search/syntax.en.ts +0 -145
  41. package/src/history.ts +0 -62
  42. package/src/import.ts +0 -114
  43. package/src/index.ts +0 -72
  44. package/src/keys.ts +0 -48
  45. package/src/links.test.ts +0 -99
  46. package/src/links.ts +0 -54
  47. package/src/login.test.ts +0 -240
  48. package/src/login.ts +0 -128
  49. package/src/loginInfo.ts +0 -43
  50. package/src/namespaceSuggestions.ts +0 -32
  51. package/src/namespaces.test.ts +0 -95
  52. package/src/namespaces.ts +0 -43
  53. package/src/notifications.ts +0 -183
  54. package/src/permissions.test.ts +0 -345
  55. package/src/permissions.ts +0 -202
  56. package/src/plugins.test.ts +0 -336
  57. package/src/plugins.ts +0 -259
  58. package/src/publicKeys.ts +0 -83
  59. package/src/repositories.test.ts +0 -508
  60. package/src/repositories.ts +0 -375
  61. package/src/repository-roles.test.ts +0 -229
  62. package/src/repository-roles.ts +0 -142
  63. package/src/reset.ts +0 -36
  64. package/src/search.ts +0 -153
  65. package/src/sources.test.ts +0 -233
  66. package/src/sources.ts +0 -136
  67. package/src/suggestions.ts +0 -47
  68. package/src/tags.test.ts +0 -272
  69. package/src/tags.ts +0 -118
  70. package/src/tests/createInfiniteCachingClient.ts +0 -37
  71. package/src/tests/createWrapper.tsx +0 -37
  72. package/src/tests/indexLinks.ts +0 -43
  73. package/src/urls.test.ts +0 -104
  74. package/src/urls.ts +0 -118
  75. package/src/usePluginCenterAuthInfo.ts +0 -91
  76. package/src/userSuggestions.ts +0 -32
  77. package/src/users.test.ts +0 -310
  78. package/src/users.ts +0 -240
  79. package/src/utils.ts +0 -29
@@ -0,0 +1,3031 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ var __export = (target, all) => {
33
+ for (var name in all)
34
+ __defProp(target, name, { get: all[name], enumerable: true });
35
+ };
36
+
37
+ // src/urls.ts
38
+ var urls_exports = {};
39
+ __export(urls_exports, {
40
+ concat: () => concat,
41
+ contextPath: () => contextPath,
42
+ escapeUrlForRoute: () => escapeUrlForRoute,
43
+ getNamespaceAndPageFromMatch: () => getNamespaceAndPageFromMatch,
44
+ getPageFromMatch: () => getPageFromMatch,
45
+ getQueryStringFromLocation: () => getQueryStringFromLocation,
46
+ matchedUrl: () => matchedUrl,
47
+ matchedUrlFromMatch: () => matchedUrlFromMatch,
48
+ stripEndingSlash: () => stripEndingSlash,
49
+ unescapeUrlForRoute: () => unescapeUrlForRoute,
50
+ withContextPath: () => withContextPath,
51
+ withEndingSlash: () => withEndingSlash,
52
+ withStartingSlash: () => withStartingSlash
53
+ });
54
+ import queryString from "query-string";
55
+ var contextPath = window.ctxPath || "";
56
+ function withContextPath(path) {
57
+ return contextPath + path;
58
+ }
59
+ function withEndingSlash(url) {
60
+ if (url.endsWith("/")) {
61
+ return url;
62
+ }
63
+ return url + "/";
64
+ }
65
+ function withStartingSlash(url) {
66
+ if (url.startsWith("/")) {
67
+ return url;
68
+ }
69
+ return "/" + url;
70
+ }
71
+ function concat(base, ...parts) {
72
+ let url = base;
73
+ for (const p of parts) {
74
+ url = withEndingSlash(url) + p;
75
+ }
76
+ return url;
77
+ }
78
+ function getNamespaceAndPageFromMatch(match) {
79
+ const namespaceFromMatch = match.params.namespace;
80
+ const pageFromMatch = match.params.page;
81
+ if (!namespaceFromMatch && !pageFromMatch) {
82
+ return { namespace: void 0, page: 1 };
83
+ }
84
+ if (!pageFromMatch) {
85
+ if (namespaceFromMatch.match(/^\d{1,3}$/)) {
86
+ return { namespace: void 0, page: parsePageNumber(namespaceFromMatch) };
87
+ } else {
88
+ return { namespace: namespaceFromMatch, page: 1 };
89
+ }
90
+ }
91
+ return { namespace: namespaceFromMatch, page: parsePageNumber(pageFromMatch) };
92
+ }
93
+ function getPageFromMatch(match) {
94
+ return parsePageNumber(match.params.page);
95
+ }
96
+ function parsePageNumber(pageAsString) {
97
+ const page = parseInt(pageAsString, 10);
98
+ if (isNaN(page) || !page) {
99
+ return 1;
100
+ }
101
+ return page;
102
+ }
103
+ function getQueryStringFromLocation(location) {
104
+ if (location.search) {
105
+ const query = queryString.parse(location.search).q;
106
+ if (query && !Array.isArray(query)) {
107
+ return query;
108
+ }
109
+ }
110
+ }
111
+ function stripEndingSlash(url) {
112
+ if (url.endsWith("/")) {
113
+ return url.substring(0, url.length - 1);
114
+ }
115
+ return url;
116
+ }
117
+ function matchedUrlFromMatch(match) {
118
+ return stripEndingSlash(match.url);
119
+ }
120
+ function matchedUrl(props) {
121
+ const match = props.match;
122
+ return matchedUrlFromMatch(match);
123
+ }
124
+ function escapeUrlForRoute(url) {
125
+ return url.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
126
+ }
127
+ function unescapeUrlForRoute(url) {
128
+ return url.replace(/\\/g, "");
129
+ }
130
+
131
+ // src/errors.ts
132
+ var BackendError = class extends Error {
133
+ constructor(content, name, statusCode) {
134
+ super(content.message);
135
+ this.context = [];
136
+ this.name = name;
137
+ this.transactionId = content.transactionId;
138
+ this.errorCode = content.errorCode;
139
+ this.url = content.url;
140
+ this.context = content.context;
141
+ this.statusCode = statusCode;
142
+ this.violations = content.violations;
143
+ this.additionalMessages = content.additionalMessages;
144
+ }
145
+ };
146
+ var UnauthorizedError = class extends Error {
147
+ constructor(message, statusCode) {
148
+ super(message);
149
+ this.statusCode = statusCode;
150
+ }
151
+ };
152
+ var BadGatewayError = class extends Error {
153
+ constructor(message, statusCode) {
154
+ super(message);
155
+ this.statusCode = statusCode;
156
+ }
157
+ };
158
+ var TokenExpiredError = class extends UnauthorizedError {
159
+ };
160
+ var ForbiddenError = class extends Error {
161
+ constructor(message, statusCode) {
162
+ super(message);
163
+ this.statusCode = statusCode;
164
+ }
165
+ };
166
+ var NotFoundError = class extends BackendError {
167
+ constructor(content, statusCode) {
168
+ super(content, "NotFoundError", statusCode);
169
+ }
170
+ };
171
+ var ConflictError = class extends BackendError {
172
+ constructor(content, statusCode) {
173
+ super(content, "ConflictError", statusCode);
174
+ }
175
+ };
176
+ var MissingLinkError = class extends Error {
177
+ constructor() {
178
+ super(...arguments);
179
+ this.name = "MissingLinkError";
180
+ }
181
+ };
182
+ function createBackendError(content, statusCode) {
183
+ switch (statusCode) {
184
+ case 404:
185
+ return new NotFoundError(content, statusCode);
186
+ case 409:
187
+ return new ConflictError(content, statusCode);
188
+ default:
189
+ return new BackendError(content, "BackendError", statusCode);
190
+ }
191
+ }
192
+ function isBackendError(response) {
193
+ return response.headers.get("Content-Type") === "application/vnd.scmm-error+json;v=2";
194
+ }
195
+ var TOKEN_EXPIRED_ERROR_CODE = "DDS8D8unr1";
196
+
197
+ // src/apiclient.ts
198
+ var sessionId = (Date.now().toString(36) + Math.random().toString(36).substr(2, 5)).toUpperCase();
199
+ var extractXsrfTokenFromJwt = (jwt) => {
200
+ const parts = jwt.split(".");
201
+ if (parts.length === 3) {
202
+ return JSON.parse(atob(parts[1])).xsrf;
203
+ }
204
+ };
205
+ var extractXsrfTokenFromCookie = (cookieString) => {
206
+ if (cookieString) {
207
+ const cookies = cookieString.split(";");
208
+ for (const c of cookies) {
209
+ const parts = c.trim().split("=");
210
+ if (parts[0] === "X-Bearer-Token" || parts[0] === "X-SCM-Init-Token") {
211
+ return extractXsrfTokenFromJwt(parts[1]);
212
+ }
213
+ }
214
+ }
215
+ };
216
+ var extractXsrfToken = () => {
217
+ return extractXsrfTokenFromCookie(document.cookie);
218
+ };
219
+ var createRequestHeaders = () => {
220
+ const headers = {
221
+ Cache: "no-cache",
222
+ "X-Requested-With": "XMLHttpRequest",
223
+ "X-SCM-Client": "WUI",
224
+ "X-SCM-Session-ID": sessionId
225
+ };
226
+ const xsrf = extractXsrfToken();
227
+ if (xsrf) {
228
+ headers["X-XSRF-Token"] = xsrf;
229
+ }
230
+ return headers;
231
+ };
232
+ var applyFetchOptions = (o) => {
233
+ if (o.headers) {
234
+ o.headers = __spreadValues({}, createRequestHeaders());
235
+ } else {
236
+ o.headers = createRequestHeaders();
237
+ }
238
+ o.credentials = "same-origin";
239
+ return o;
240
+ };
241
+ function handleFailure(response) {
242
+ if (!response.ok) {
243
+ if (response.status === 401) {
244
+ if (isBackendError(response)) {
245
+ return response.json().then((content) => {
246
+ if (content.errorCode === TOKEN_EXPIRED_ERROR_CODE) {
247
+ throw new TokenExpiredError("Token expired", 401);
248
+ } else {
249
+ throw new UnauthorizedError("Unauthorized", 401);
250
+ }
251
+ });
252
+ }
253
+ throw new UnauthorizedError("Unauthorized", 401);
254
+ } else if (response.status === 403) {
255
+ throw new ForbiddenError("Forbidden", 403);
256
+ } else if (response.status === 502) {
257
+ throw new BadGatewayError("Bad Gateway", 502);
258
+ } else if (isBackendError(response)) {
259
+ return response.json().then((content) => {
260
+ throw createBackendError(content, response.status);
261
+ });
262
+ } else {
263
+ throw new Error("server returned status code " + response.status);
264
+ }
265
+ }
266
+ return response;
267
+ }
268
+ function createUrl(url) {
269
+ if (url.includes("://")) {
270
+ return url;
271
+ }
272
+ let urlWithStartingSlash = url;
273
+ if (url.indexOf("/") !== 0) {
274
+ urlWithStartingSlash = "/" + urlWithStartingSlash;
275
+ }
276
+ return `${contextPath}/api/v2${urlWithStartingSlash}`;
277
+ }
278
+ function createUrlWithIdentifiers(url) {
279
+ return createUrl(url) + "?X-SCM-Client=WUI&X-SCM-Session-ID=" + sessionId;
280
+ }
281
+ var ApiClient = class {
282
+ constructor() {
283
+ this.errorListeners = [];
284
+ this.requestListeners = [];
285
+ this.get = (url) => {
286
+ return this.request(url, applyFetchOptions({})).then(handleFailure).catch(this.notifyAndRethrow);
287
+ };
288
+ this.post = (url, payload, contentType = "application/json", additionalHeaders = {}) => {
289
+ return this.httpRequestWithJSONBody("POST", url, contentType, additionalHeaders, payload);
290
+ };
291
+ this.postText = (url, payload, additionalHeaders = {}) => {
292
+ return this.httpRequestWithTextBody("POST", url, additionalHeaders, payload);
293
+ };
294
+ this.putText = (url, payload, additionalHeaders = {}) => {
295
+ return this.httpRequestWithTextBody("PUT", url, additionalHeaders, payload);
296
+ };
297
+ this.postBinary = (url, fileAppender, additionalHeaders = {}) => {
298
+ const formData = new FormData();
299
+ fileAppender(formData);
300
+ const options = {
301
+ method: "POST",
302
+ body: formData,
303
+ headers: additionalHeaders
304
+ };
305
+ return this.httpRequestWithBinaryBody(options, url);
306
+ };
307
+ this.head = (url) => {
308
+ let options = {
309
+ method: "HEAD"
310
+ };
311
+ options = applyFetchOptions(options);
312
+ return this.request(url, options).then(handleFailure).catch(this.notifyAndRethrow);
313
+ };
314
+ this.delete = (url) => {
315
+ let options = {
316
+ method: "DELETE"
317
+ };
318
+ options = applyFetchOptions(options);
319
+ return this.request(url, options).then(handleFailure).catch(this.notifyAndRethrow);
320
+ };
321
+ this.httpRequestWithJSONBody = (method, url, contentType, additionalHeaders, payload) => {
322
+ const options = {
323
+ method,
324
+ headers: additionalHeaders
325
+ };
326
+ if (payload) {
327
+ options.body = JSON.stringify(payload);
328
+ }
329
+ return this.httpRequestWithBinaryBody(options, url, contentType);
330
+ };
331
+ this.httpRequestWithTextBody = (method, url, additionalHeaders = {}, payload) => {
332
+ const options = {
333
+ method,
334
+ headers: additionalHeaders
335
+ };
336
+ options.body = payload;
337
+ return this.httpRequestWithBinaryBody(options, url, "text/plain");
338
+ };
339
+ this.httpRequestWithBinaryBody = (options, url, contentType) => {
340
+ options = applyFetchOptions(options);
341
+ if (contentType) {
342
+ if (!options.headers) {
343
+ options.headers = {};
344
+ }
345
+ options.headers["Content-Type"] = contentType;
346
+ }
347
+ return this.request(url, options).then(handleFailure).catch(this.notifyAndRethrow);
348
+ };
349
+ this.onRequest = (requestListener) => {
350
+ this.requestListeners.push(requestListener);
351
+ };
352
+ this.onError = (errorListener) => {
353
+ this.errorListeners.push(errorListener);
354
+ };
355
+ this.request = (url, options) => {
356
+ this.notifyRequestListeners(url, options);
357
+ return fetch(createUrl(url), options);
358
+ };
359
+ this.notifyRequestListeners = (url, options) => {
360
+ this.requestListeners.forEach((requestListener) => requestListener(url, options));
361
+ };
362
+ this.notifyAndRethrow = (error) => {
363
+ this.errorListeners.forEach((errorListener) => errorListener(error));
364
+ throw error;
365
+ };
366
+ }
367
+ put(url, payload, contentType = "application/json", additionalHeaders = {}) {
368
+ return this.httpRequestWithJSONBody("PUT", url, contentType, additionalHeaders, payload);
369
+ }
370
+ subscribe(url, argument) {
371
+ const es = new EventSource(createUrlWithIdentifiers(url), {
372
+ withCredentials: true
373
+ });
374
+ let listeners;
375
+ if ("onMessage" in argument) {
376
+ listeners = argument.onMessage;
377
+ if (argument.onError) {
378
+ es.onerror = argument.onError;
379
+ }
380
+ if (argument.onOpen) {
381
+ es.onopen = argument.onOpen;
382
+ }
383
+ } else {
384
+ listeners = argument;
385
+ }
386
+ for (const type in listeners) {
387
+ es.addEventListener(type, listeners[type]);
388
+ }
389
+ return () => es.close();
390
+ }
391
+ };
392
+ var apiClient = new ApiClient();
393
+
394
+ // src/base.ts
395
+ import { useQuery } from "react-query";
396
+
397
+ // src/LegacyContext.tsx
398
+ import React, { createContext, useContext } from "react";
399
+ import { useQueryClient } from "react-query";
400
+ var Context = createContext(void 0);
401
+ var useLegacyContext = () => {
402
+ const context = useContext(Context);
403
+ if (!context) {
404
+ throw new Error("useLegacyContext can't be used outside of ApiProvider");
405
+ }
406
+ return context;
407
+ };
408
+ var createInitialContext = (queryClient2, base) => {
409
+ const ctx = __spreadProps(__spreadValues({}, base), {
410
+ initialize: () => {
411
+ if (ctx.onIndexFetched) {
412
+ const index = queryClient2.getQueryData("index");
413
+ if (index) {
414
+ ctx.onIndexFetched(index);
415
+ }
416
+ }
417
+ if (ctx.onMeFetched) {
418
+ const me = queryClient2.getQueryData("me");
419
+ if (me) {
420
+ ctx.onMeFetched(me);
421
+ }
422
+ }
423
+ }
424
+ });
425
+ return ctx;
426
+ };
427
+ var LegacyContextProvider = ({ onIndexFetched, onMeFetched, children }) => {
428
+ const queryClient2 = useQueryClient();
429
+ const ctx = createInitialContext(queryClient2, { onIndexFetched, onMeFetched });
430
+ return /* @__PURE__ */ React.createElement(Context.Provider, {
431
+ value: ctx
432
+ }, children);
433
+ };
434
+
435
+ // src/links.ts
436
+ var requiredLink = (object, name, subName) => {
437
+ const link = object._links[name];
438
+ if (!link) {
439
+ throw new MissingLinkError(`could not find link with name ${name}`);
440
+ }
441
+ if (Array.isArray(link)) {
442
+ if (subName) {
443
+ const subLink = link.find((l) => l.name === subName);
444
+ if (subLink) {
445
+ return subLink.href;
446
+ }
447
+ throw new Error(`could not return href, sub-link ${subName} in ${name} does not exist`);
448
+ }
449
+ throw new Error(`could not return href, link ${name} is a multi link`);
450
+ }
451
+ return link.href;
452
+ };
453
+ var objectLink = (object, name) => {
454
+ const link = object._links[name];
455
+ if (!link) {
456
+ return null;
457
+ }
458
+ if (Array.isArray(link)) {
459
+ throw new Error(`could not return href, link ${name} is a multi link`);
460
+ }
461
+ return link.href;
462
+ };
463
+
464
+ // src/base.ts
465
+ var useIndex = () => {
466
+ const legacy = useLegacyContext();
467
+ return useQuery("index", () => apiClient.get("/").then((response) => response.json()), {
468
+ onSuccess: (index) => {
469
+ if (legacy.onIndexFetched) {
470
+ legacy.onIndexFetched(index);
471
+ }
472
+ },
473
+ refetchOnMount: false,
474
+ retry: (failureCount, error) => {
475
+ return error instanceof UnauthorizedError && failureCount === 0;
476
+ }
477
+ });
478
+ };
479
+ var useIndexLink = (name) => {
480
+ const { data } = useIndex();
481
+ if (!data) {
482
+ throw new Error("could not find index data");
483
+ }
484
+ const linkObject = data._links[name];
485
+ if (linkObject && linkObject.href) {
486
+ return linkObject.href;
487
+ }
488
+ };
489
+ var useIndexLinks = () => {
490
+ const { data } = useIndex();
491
+ if (!data) {
492
+ throw new Error("could not find index data");
493
+ }
494
+ return data._links;
495
+ };
496
+ var useRequiredIndexLink = (name) => {
497
+ const link = useIndexLink(name);
498
+ if (!link) {
499
+ throw new MissingLinkError(`Could not find link ${name} in index resource`);
500
+ }
501
+ return link;
502
+ };
503
+ var useVersion = () => {
504
+ const { data } = useIndex();
505
+ if (!data) {
506
+ throw new Error("could not find index data");
507
+ }
508
+ const { version } = data;
509
+ if (!version) {
510
+ throw new Error("could not find version in index data");
511
+ }
512
+ return version;
513
+ };
514
+ var useIndexJsonResource = (name) => {
515
+ const link = useIndexLink(name);
516
+ return useQuery(name, () => apiClient.get(link).then((response) => response.json()), {
517
+ enabled: !!link
518
+ });
519
+ };
520
+ var useJsonResource = (entity, name, key) => useQuery(key, () => apiClient.get(requiredLink(entity, name)).then((response) => response.json()));
521
+ function fetchResourceFromLocationHeader(response) {
522
+ const location = response.headers.get("Location");
523
+ if (!location) {
524
+ throw new Error("Server does not return required Location header");
525
+ }
526
+ return apiClient.get(location);
527
+ }
528
+ var getResponseJson = (response) => response.json();
529
+
530
+ // src/login.ts
531
+ import { useMutation, useQuery as useQuery2 } from "react-query";
532
+
533
+ // src/reset.ts
534
+ import { useQueryClient as useQueryClient2 } from "react-query";
535
+ var reset = (queryClient2) => {
536
+ queryClient2.removeQueries({
537
+ predicate: ({ queryKey }) => queryKey !== "index"
538
+ });
539
+ return queryClient2.invalidateQueries("index");
540
+ };
541
+ var useReset = () => {
542
+ const queryClient2 = useQueryClient2();
543
+ return () => reset(queryClient2);
544
+ };
545
+
546
+ // src/login.ts
547
+ import { useCallback } from "react";
548
+ var useMe = () => {
549
+ const legacy = useLegacyContext();
550
+ const link = useIndexLink("me");
551
+ return useQuery2("me", () => apiClient.get(link).then((response) => response.json()), {
552
+ enabled: !!link,
553
+ onSuccess: (me) => {
554
+ if (legacy.onMeFetched) {
555
+ legacy.onMeFetched(me);
556
+ }
557
+ }
558
+ });
559
+ };
560
+ var useRequiredMe = () => {
561
+ const { data } = useMe();
562
+ if (!data) {
563
+ throw new Error("Could not find 'me' in cache");
564
+ }
565
+ return data;
566
+ };
567
+ var useSubject = () => {
568
+ const link = useIndexLink("login");
569
+ const { isLoading, error, data: me } = useMe();
570
+ const isAnonymous = (me == null ? void 0 : me.name) === "_anonymous";
571
+ const isAuthenticated = !isAnonymous && !!me && !link;
572
+ return {
573
+ isAuthenticated,
574
+ isAnonymous,
575
+ isLoading,
576
+ error,
577
+ me
578
+ };
579
+ };
580
+ var useLogin = () => {
581
+ const link = useIndexLink("login");
582
+ const reset2 = useReset();
583
+ const { mutate, isLoading, error } = useMutation((credentials) => apiClient.post(link, credentials), {
584
+ onSuccess: reset2
585
+ });
586
+ const login = (username, password) => {
587
+ mutate({ cookie: true, grant_type: "password", username, password });
588
+ };
589
+ return {
590
+ login: link ? login : void 0,
591
+ isLoading,
592
+ error
593
+ };
594
+ };
595
+ var useLogout = () => {
596
+ const link = useIndexLink("logout");
597
+ const reset2 = useReset();
598
+ const { mutate, isLoading, error, data } = useMutation(() => apiClient.delete(link).then((r) => r.status === 200 ? r.json() : {}), {
599
+ onSuccess: (response) => {
600
+ if (response == null ? void 0 : response.logoutRedirect) {
601
+ window.location.assign(response.logoutRedirect);
602
+ }
603
+ return reset2();
604
+ }
605
+ });
606
+ const logout = useCallback(() => {
607
+ mutate({});
608
+ }, [mutate]);
609
+ return {
610
+ logout: link && !data ? logout : void 0,
611
+ isLoading,
612
+ error
613
+ };
614
+ };
615
+
616
+ // src/groups.ts
617
+ import { useMutation as useMutation2, useQuery as useQuery3, useQueryClient as useQueryClient3 } from "react-query";
618
+
619
+ // src/utils.ts
620
+ var createQueryString = (params) => {
621
+ return Object.keys(params).map((k) => encodeURIComponent(k) + "=" + encodeURIComponent(params[k])).join("&");
622
+ };
623
+
624
+ // src/groups.ts
625
+ var useGroups = (request) => {
626
+ const queryClient2 = useQueryClient3();
627
+ const indexLink = useRequiredIndexLink("groups");
628
+ const queryParams = {};
629
+ if (request == null ? void 0 : request.search) {
630
+ queryParams.q = request.search;
631
+ }
632
+ if (request == null ? void 0 : request.page) {
633
+ queryParams.page = request.page.toString();
634
+ }
635
+ return useQuery3(["groups", (request == null ? void 0 : request.search) || "", (request == null ? void 0 : request.page) || 0], () => apiClient.get(`${indexLink}?${createQueryString(queryParams)}`).then((response) => response.json()), {
636
+ onSuccess: (groups) => {
637
+ groups._embedded.groups.forEach((group) => queryClient2.setQueryData(["group", group.name], group));
638
+ }
639
+ });
640
+ };
641
+ var useGroup = (name) => {
642
+ const indexLink = useRequiredIndexLink("groups");
643
+ return useQuery3(["group", name], () => apiClient.get(concat(indexLink, name)).then((response) => response.json()));
644
+ };
645
+ var createGroup = (link) => {
646
+ return (group) => {
647
+ return apiClient.post(link, group, "application/vnd.scmm-group+json;v=2").then((response) => {
648
+ const location = response.headers.get("Location");
649
+ if (!location) {
650
+ throw new Error("Server does not return required Location header");
651
+ }
652
+ return apiClient.get(location);
653
+ }).then((response) => response.json());
654
+ };
655
+ };
656
+ var useCreateGroup = () => {
657
+ const queryClient2 = useQueryClient3();
658
+ const link = useRequiredIndexLink("groups");
659
+ const { mutate, data, isLoading, error } = useMutation2(createGroup(link), {
660
+ onSuccess: (group) => {
661
+ queryClient2.setQueryData(["group", group.name], group);
662
+ return queryClient2.invalidateQueries(["groups"]);
663
+ }
664
+ });
665
+ return {
666
+ create: (group) => mutate(group),
667
+ isLoading,
668
+ error,
669
+ group: data
670
+ };
671
+ };
672
+ var useUpdateGroup = () => {
673
+ const queryClient2 = useQueryClient3();
674
+ const { mutate, isLoading, error, data } = useMutation2((group) => {
675
+ const updateUrl = group._links.update.href;
676
+ return apiClient.put(updateUrl, group, "application/vnd.scmm-group+json;v=2");
677
+ }, {
678
+ onSuccess: async (_, group) => {
679
+ await queryClient2.invalidateQueries(["group", group.name]);
680
+ await queryClient2.invalidateQueries(["groups"]);
681
+ }
682
+ });
683
+ return {
684
+ update: (group) => mutate(group),
685
+ isLoading,
686
+ error,
687
+ isUpdated: !!data
688
+ };
689
+ };
690
+ var useDeleteGroup = () => {
691
+ const queryClient2 = useQueryClient3();
692
+ const { mutate, isLoading, error, data } = useMutation2((group) => {
693
+ const deleteUrl = group._links.delete.href;
694
+ return apiClient.delete(deleteUrl);
695
+ }, {
696
+ onSuccess: async (_, name) => {
697
+ await queryClient2.removeQueries(["group", name]);
698
+ await queryClient2.invalidateQueries(["groups"]);
699
+ }
700
+ });
701
+ return {
702
+ remove: (group) => mutate(group),
703
+ isLoading,
704
+ error,
705
+ isDeleted: !!data
706
+ };
707
+ };
708
+
709
+ // src/users.ts
710
+ import { useMutation as useMutation3, useQuery as useQuery4, useQueryClient as useQueryClient4 } from "react-query";
711
+ var useUsers = (request) => {
712
+ const queryClient2 = useQueryClient4();
713
+ const indexLink = useRequiredIndexLink("users");
714
+ const queryParams = {};
715
+ if (request == null ? void 0 : request.search) {
716
+ queryParams.q = request.search;
717
+ }
718
+ if (request == null ? void 0 : request.page) {
719
+ queryParams.page = request.page.toString();
720
+ }
721
+ return useQuery4(["users", (request == null ? void 0 : request.search) || "", (request == null ? void 0 : request.page) || 0], () => apiClient.get(`${indexLink}?${createQueryString(queryParams)}`).then((response) => response.json()), {
722
+ onSuccess: (users) => {
723
+ var _a;
724
+ (_a = users._embedded) == null ? void 0 : _a.users.forEach((user) => queryClient2.setQueryData(["user", user.name], user));
725
+ }
726
+ });
727
+ };
728
+ var useUser = (name) => {
729
+ const indexLink = useRequiredIndexLink("users");
730
+ return useQuery4(["user", name], () => apiClient.get(concat(indexLink, name)).then((response) => response.json()));
731
+ };
732
+ var createUser = (link) => {
733
+ return (user) => {
734
+ return apiClient.post(link, user, "application/vnd.scmm-user+json;v=2").then((response) => {
735
+ const location = response.headers.get("Location");
736
+ if (!location) {
737
+ throw new Error("Server does not return required Location header");
738
+ }
739
+ return apiClient.get(location);
740
+ }).then((response) => response.json());
741
+ };
742
+ };
743
+ var useCreateUser = () => {
744
+ const queryClient2 = useQueryClient4();
745
+ const link = useRequiredIndexLink("users");
746
+ const { mutate, data, isLoading, error } = useMutation3(createUser(link), {
747
+ onSuccess: (user) => {
748
+ queryClient2.setQueryData(["user", user.name], user);
749
+ return queryClient2.invalidateQueries(["users"]);
750
+ }
751
+ });
752
+ return {
753
+ create: (user) => mutate(user),
754
+ isLoading,
755
+ error,
756
+ user: data
757
+ };
758
+ };
759
+ var useUpdateUser = () => {
760
+ const queryClient2 = useQueryClient4();
761
+ const { mutate, isLoading, error, data } = useMutation3((user) => {
762
+ const updateUrl = user._links.update.href;
763
+ return apiClient.put(updateUrl, user, "application/vnd.scmm-user+json;v=2");
764
+ }, {
765
+ onSuccess: async (_, user) => {
766
+ await queryClient2.invalidateQueries(["user", user.name]);
767
+ await queryClient2.invalidateQueries(["users"]);
768
+ }
769
+ });
770
+ return {
771
+ update: (user) => mutate(user),
772
+ isLoading,
773
+ error,
774
+ isUpdated: !!data
775
+ };
776
+ };
777
+ var useDeleteUser = () => {
778
+ const queryClient2 = useQueryClient4();
779
+ const { mutate, isLoading, error, data } = useMutation3((user) => {
780
+ const deleteUrl = user._links.delete.href;
781
+ return apiClient.delete(deleteUrl);
782
+ }, {
783
+ onSuccess: async (_, name) => {
784
+ await queryClient2.removeQueries(["user", name]);
785
+ await queryClient2.invalidateQueries(["users"]);
786
+ }
787
+ });
788
+ return {
789
+ remove: (user) => mutate(user),
790
+ isLoading,
791
+ error,
792
+ isDeleted: !!data
793
+ };
794
+ };
795
+ var convertToInternal = (url, newPassword) => {
796
+ return apiClient.put(url, {
797
+ newPassword
798
+ }, "application/vnd.scmm-user+json;v=2");
799
+ };
800
+ var convertToExternal = (url) => {
801
+ return apiClient.put(url, {}, "application/vnd.scmm-user+json;v=2");
802
+ };
803
+ var useConvertToInternal = () => {
804
+ const queryClient2 = useQueryClient4();
805
+ const { mutate, isLoading, error, data } = useMutation3(({ user, password }) => convertToInternal(user._links.convertToInternal.href, password), {
806
+ onSuccess: async (_, { user }) => {
807
+ await queryClient2.invalidateQueries(["user", user.name]);
808
+ await queryClient2.invalidateQueries(["users"]);
809
+ }
810
+ });
811
+ return {
812
+ convertToInternal: (user, password) => mutate({ user, password }),
813
+ isLoading,
814
+ error,
815
+ isConverted: !!data
816
+ };
817
+ };
818
+ var useConvertToExternal = () => {
819
+ const queryClient2 = useQueryClient4();
820
+ const { mutate, isLoading, error, data } = useMutation3((user) => convertToExternal(user._links.convertToExternal.href), {
821
+ onSuccess: async (_, user) => {
822
+ await queryClient2.invalidateQueries(["user", user.name]);
823
+ await queryClient2.invalidateQueries(["users"]);
824
+ }
825
+ });
826
+ return {
827
+ convertToExternal: (user) => mutate(user),
828
+ isLoading,
829
+ error,
830
+ isConverted: !!data
831
+ };
832
+ };
833
+ var CONTENT_TYPE_PASSWORD_OVERWRITE = "application/vnd.scmm-passwordOverwrite+json;v=2";
834
+ var useSetUserPassword = (user) => {
835
+ const { data, isLoading, error, mutate, reset: reset2 } = useMutation3((password) => apiClient.put(requiredLink(user, "password"), {
836
+ newPassword: password
837
+ }, CONTENT_TYPE_PASSWORD_OVERWRITE));
838
+ return {
839
+ setPassword: (newPassword) => mutate(newPassword),
840
+ passwordOverwritten: !!data,
841
+ isLoading,
842
+ error,
843
+ reset: reset2
844
+ };
845
+ };
846
+ var CONTENT_TYPE_PASSWORD_CHANGE = "application/vnd.scmm-passwordChange+json;v=2";
847
+ var useChangeUserPassword = (user) => {
848
+ const { data, isLoading, error, mutate, reset: reset2 } = useMutation3((request) => apiClient.put(requiredLink(user, "password"), request, CONTENT_TYPE_PASSWORD_CHANGE));
849
+ return {
850
+ changePassword: (oldPassword, newPassword) => mutate({ oldPassword, newPassword }),
851
+ passwordChanged: !!data,
852
+ isLoading,
853
+ error,
854
+ reset: reset2
855
+ };
856
+ };
857
+
858
+ // src/suggestions.ts
859
+ var useSuggestions = (link) => {
860
+ if (!link) {
861
+ return () => Promise.resolve([]);
862
+ }
863
+ const url = link + "?q=";
864
+ return (inputValue) => {
865
+ if (inputValue.length < 2) {
866
+ return Promise.resolve([]);
867
+ }
868
+ return apiClient.get(url + inputValue).then((response) => response.json()).then((json) => json.map((element) => ({
869
+ value: element,
870
+ label: element.displayName ? `${element.displayName} (${element.id})` : element.id
871
+ })));
872
+ };
873
+ };
874
+
875
+ // src/userSuggestions.ts
876
+ var useUserSuggestions = () => {
877
+ const indexLinks = useIndexLinks();
878
+ const autocompleteLink = indexLinks.autocomplete.find((i) => i.name === "users");
879
+ return useSuggestions(autocompleteLink == null ? void 0 : autocompleteLink.href);
880
+ };
881
+
882
+ // src/groupSuggestions.ts
883
+ var useGroupSuggestions = () => {
884
+ const indexLinks = useIndexLinks();
885
+ const autocompleteLink = indexLinks.autocomplete.find((i) => i.name === "groups");
886
+ return useSuggestions(autocompleteLink == null ? void 0 : autocompleteLink.href);
887
+ };
888
+
889
+ // src/namespaceSuggestions.ts
890
+ var useNamespaceSuggestions = () => {
891
+ const indexLinks = useIndexLinks();
892
+ const autocompleteLink = indexLinks.autocomplete.find((i) => i.name === "namespaces");
893
+ return useSuggestions(autocompleteLink == null ? void 0 : autocompleteLink.href);
894
+ };
895
+
896
+ // src/repositories.ts
897
+ import { useMutation as useMutation4, useQuery as useQuery5, useQueryClient as useQueryClient5 } from "react-query";
898
+
899
+ // src/keys.ts
900
+ var repoQueryKey = (repository, ...values) => {
901
+ return ["repository", repository.namespace, repository.name, ...values];
902
+ };
903
+ var isBranch = (branch) => {
904
+ return branch.name !== void 0;
905
+ };
906
+ var branchQueryKey = (repository, branch, ...values) => {
907
+ let branchName;
908
+ if (!branch) {
909
+ branchName = "_";
910
+ } else if (isBranch(branch)) {
911
+ branchName = branch.name;
912
+ } else {
913
+ branchName = branch;
914
+ }
915
+ return [...repoQueryKey(repository), "branch", branchName, ...values];
916
+ };
917
+
918
+ // src/repositories.ts
919
+ import { useEffect, useState } from "react";
920
+ var useRepositories = (request) => {
921
+ var _a, _b, _c;
922
+ const queryClient2 = useQueryClient5();
923
+ const indexLink = useRequiredIndexLink("repositories");
924
+ const namespaceLink = (_b = (_a = request == null ? void 0 : request.namespace) == null ? void 0 : _a._links.repositories) == null ? void 0 : _b.href;
925
+ const link = namespaceLink || indexLink;
926
+ const queryParams = {};
927
+ if (request == null ? void 0 : request.search) {
928
+ queryParams.q = request.search;
929
+ }
930
+ if (request == null ? void 0 : request.page) {
931
+ queryParams.page = request.page.toString();
932
+ }
933
+ return useQuery5(["repositories", (_c = request == null ? void 0 : request.namespace) == null ? void 0 : _c.namespace, (request == null ? void 0 : request.search) || "", (request == null ? void 0 : request.page) || 0], () => apiClient.get(`${link}?${createQueryString(queryParams)}`).then((response) => response.json()), {
934
+ enabled: !(request == null ? void 0 : request.disabled),
935
+ onSuccess: (repositories) => {
936
+ var _a2;
937
+ (_a2 = repositories._embedded) == null ? void 0 : _a2.repositories.forEach((repository) => {
938
+ queryClient2.setQueryData(["repository", repository.namespace, repository.name], repository);
939
+ });
940
+ }
941
+ });
942
+ };
943
+ var createRepository = (link) => {
944
+ return (request) => {
945
+ let createLink = link;
946
+ if (request.initialize) {
947
+ createLink += "?initialize=true";
948
+ }
949
+ return apiClient.post(createLink, request.repository, "application/vnd.scmm-repository+json;v=2").then((response) => {
950
+ const location = response.headers.get("Location");
951
+ if (!location) {
952
+ throw new Error("Server does not return required Location header");
953
+ }
954
+ return apiClient.get(location);
955
+ }).then((response) => response.json());
956
+ };
957
+ };
958
+ var useCreateRepository = () => {
959
+ const queryClient2 = useQueryClient5();
960
+ const link = useRequiredIndexLink("repositories");
961
+ const { mutate, data, isLoading, error } = useMutation4(createRepository(link), {
962
+ onSuccess: (repository) => {
963
+ queryClient2.setQueryData(["repository", repository.namespace, repository.name], repository);
964
+ return queryClient2.invalidateQueries(["repositories"]);
965
+ }
966
+ });
967
+ return {
968
+ create: (repository, initialize) => {
969
+ mutate({ repository, initialize });
970
+ },
971
+ isLoading,
972
+ error,
973
+ repository: data
974
+ };
975
+ };
976
+ var useRepositoryTypes = () => useIndexJsonResource("repositoryTypes");
977
+ var useRepository = (namespace, name) => {
978
+ const link = useRequiredIndexLink("repositories");
979
+ return useQuery5(["repository", namespace, name], () => apiClient.get(concat(link, namespace, name)).then((response) => response.json()));
980
+ };
981
+ var useDeleteRepository = (options) => {
982
+ const queryClient2 = useQueryClient5();
983
+ const { mutate, isLoading, error, data } = useMutation4((repository) => {
984
+ const link = requiredLink(repository, "delete");
985
+ return apiClient.delete(link);
986
+ }, {
987
+ onSuccess: async (_, repository) => {
988
+ if (options == null ? void 0 : options.onSuccess) {
989
+ options.onSuccess(repository);
990
+ }
991
+ queryClient2.removeQueries(repoQueryKey(repository));
992
+ await queryClient2.invalidateQueries(["repositories"]);
993
+ }
994
+ });
995
+ return {
996
+ remove: (repository) => mutate(repository),
997
+ isLoading,
998
+ error,
999
+ isDeleted: !!data
1000
+ };
1001
+ };
1002
+ var useUpdateRepository = () => {
1003
+ const queryClient2 = useQueryClient5();
1004
+ const { mutate, isLoading, error, data } = useMutation4((repository) => {
1005
+ const link = requiredLink(repository, "update");
1006
+ return apiClient.put(link, repository, "application/vnd.scmm-repository+json;v=2");
1007
+ }, {
1008
+ onSuccess: async (_, repository) => {
1009
+ await queryClient2.invalidateQueries(repoQueryKey(repository));
1010
+ await queryClient2.invalidateQueries(["repositories"]);
1011
+ }
1012
+ });
1013
+ return {
1014
+ update: (repository) => mutate(repository),
1015
+ isLoading,
1016
+ error,
1017
+ isUpdated: !!data
1018
+ };
1019
+ };
1020
+ var useArchiveRepository = () => {
1021
+ const queryClient2 = useQueryClient5();
1022
+ const { mutate, isLoading, error, data } = useMutation4((repository) => {
1023
+ const link = requiredLink(repository, "archive");
1024
+ return apiClient.post(link);
1025
+ }, {
1026
+ onSuccess: async (_, repository) => {
1027
+ await queryClient2.invalidateQueries(repoQueryKey(repository));
1028
+ await queryClient2.invalidateQueries(["repositories"]);
1029
+ }
1030
+ });
1031
+ return {
1032
+ archive: (repository) => mutate(repository),
1033
+ isLoading,
1034
+ error,
1035
+ isArchived: !!data
1036
+ };
1037
+ };
1038
+ var useUnarchiveRepository = () => {
1039
+ const queryClient2 = useQueryClient5();
1040
+ const { mutate, isLoading, error, data } = useMutation4((repository) => {
1041
+ const link = requiredLink(repository, "unarchive");
1042
+ return apiClient.post(link);
1043
+ }, {
1044
+ onSuccess: async (_, repository) => {
1045
+ await queryClient2.invalidateQueries(repoQueryKey(repository));
1046
+ await queryClient2.invalidateQueries(["repositories"]);
1047
+ }
1048
+ });
1049
+ return {
1050
+ unarchive: (repository) => mutate(repository),
1051
+ isLoading,
1052
+ error,
1053
+ isUnarchived: !!data
1054
+ };
1055
+ };
1056
+ var useRunHealthCheck = () => {
1057
+ const queryClient2 = useQueryClient5();
1058
+ const { mutate, isLoading, error, data } = useMutation4((repository) => {
1059
+ const link = requiredLink(repository, "runHealthCheck");
1060
+ return apiClient.post(link);
1061
+ }, {
1062
+ onSuccess: async (_, repository) => {
1063
+ await queryClient2.invalidateQueries(repoQueryKey(repository));
1064
+ }
1065
+ });
1066
+ return {
1067
+ runHealthCheck: (repository) => mutate(repository),
1068
+ isLoading,
1069
+ error,
1070
+ isRunning: !!data
1071
+ };
1072
+ };
1073
+ var useExportInfo = (repository) => {
1074
+ const link = requiredLink(repository, "exportInfo");
1075
+ const { isLoading, isFetching, error, data } = useQuery5(["repository", repository.namespace, repository.name, "exportInfo"], () => apiClient.get(link).then((response) => response.json()), {});
1076
+ return {
1077
+ isLoading,
1078
+ isFetching,
1079
+ error: error instanceof NotFoundError ? null : error,
1080
+ data
1081
+ };
1082
+ };
1083
+ var EXPORT_MEDIA_TYPE = "application/vnd.scmm-repositoryExport+json;v=2";
1084
+ var useExportRepository = () => {
1085
+ const queryClient2 = useQueryClient5();
1086
+ const [intervalId, setIntervalId] = useState();
1087
+ useEffect(() => {
1088
+ return () => {
1089
+ if (intervalId) {
1090
+ clearInterval(intervalId);
1091
+ }
1092
+ };
1093
+ }, [intervalId]);
1094
+ const { mutate, isLoading, error, data } = useMutation4(({ repository, options }) => {
1095
+ const infolink = requiredLink(repository, "exportInfo");
1096
+ let link = requiredLink(repository, options.withMetadata ? "fullExport" : "export");
1097
+ if (options.compressed) {
1098
+ link += "?compressed=true";
1099
+ }
1100
+ return apiClient.post(link, { password: options.password, async: true }, EXPORT_MEDIA_TYPE).then(() => queryClient2.invalidateQueries(repoQueryKey(repository))).then(() => queryClient2.invalidateQueries(["repositories"])).then(() => {
1101
+ return new Promise((resolve, reject) => {
1102
+ const id = setInterval(() => {
1103
+ apiClient.get(infolink).then((r) => r.json()).then((info) => {
1104
+ if (info._links.download) {
1105
+ clearInterval(id);
1106
+ resolve(info);
1107
+ }
1108
+ }).catch((e) => {
1109
+ clearInterval(id);
1110
+ reject(e);
1111
+ });
1112
+ }, 1e3);
1113
+ setIntervalId(id);
1114
+ });
1115
+ });
1116
+ }, {
1117
+ onSuccess: async (_, { repository }) => {
1118
+ await queryClient2.invalidateQueries(repoQueryKey(repository));
1119
+ await queryClient2.invalidateQueries(["repositories"]);
1120
+ }
1121
+ });
1122
+ return {
1123
+ exportRepository: (repository, options) => mutate({ repository, options }),
1124
+ isLoading,
1125
+ error,
1126
+ data
1127
+ };
1128
+ };
1129
+ var usePaths = (repository, revision) => {
1130
+ const link = requiredLink(repository, "paths").replace("{revision}", revision);
1131
+ return useQuery5(repoQueryKey(repository, "paths", revision), () => apiClient.get(link).then((response) => response.json()));
1132
+ };
1133
+ var useRenameRepository = (repository) => {
1134
+ const queryClient2 = useQueryClient5();
1135
+ const url = objectLink(repository, "renameWithNamespace") || objectLink(repository, "rename");
1136
+ if (!url) {
1137
+ throw new MissingLinkError(`could not find rename link on repository ${repository.namespace}/${repository.name}`);
1138
+ }
1139
+ const { mutate, isLoading, error, data } = useMutation4(({ name, namespace }) => apiClient.post(url, { namespace, name }, "application/vnd.scmm-repository+json;v=2"), {
1140
+ onSuccess: () => queryClient2.removeQueries(repoQueryKey(repository))
1141
+ });
1142
+ return {
1143
+ renameRepository: (namespace, name) => mutate({ namespace, name }),
1144
+ isLoading,
1145
+ error,
1146
+ isRenamed: !!data
1147
+ };
1148
+ };
1149
+
1150
+ // src/namespaces.ts
1151
+ import { useQuery as useQuery6 } from "react-query";
1152
+ var useNamespaces = () => {
1153
+ return useIndexJsonResource("namespaces");
1154
+ };
1155
+ var useNamespace = (name) => {
1156
+ const namespacesLink = useRequiredIndexLink("namespaces");
1157
+ return useQuery6(["namespace", name], () => apiClient.get(concat(namespacesLink, name)).then((response) => response.json()));
1158
+ };
1159
+ var useNamespaceStrategies = () => {
1160
+ return useIndexJsonResource("namespaceStrategies");
1161
+ };
1162
+
1163
+ // src/branches.ts
1164
+ import { useInfiniteQuery, useMutation as useMutation5, useQuery as useQuery7, useQueryClient as useQueryClient6 } from "react-query";
1165
+ import { useEffect as useEffect2 } from "react";
1166
+ var useBranches = (repository) => {
1167
+ const queryClient2 = useQueryClient6();
1168
+ const link = requiredLink(repository, "branches");
1169
+ return useQuery7(repoQueryKey(repository, "branches"), () => apiClient.get(link).then((response) => response.json()), {
1170
+ onSuccess: () => {
1171
+ return queryClient2.invalidateQueries(branchDetailsQueryKey(repository));
1172
+ }
1173
+ });
1174
+ };
1175
+ var useBranch = (repository, name) => {
1176
+ const link = requiredLink(repository, "branches");
1177
+ return useQuery7(branchQueryKey(repository, name), () => apiClient.get(concat(link, encodeURIComponent(name))).then((response) => response.json()));
1178
+ };
1179
+ function chunkBranches(branches) {
1180
+ const chunks = [];
1181
+ const chunkSize = 5;
1182
+ let chunkIndex = 0;
1183
+ for (const branch of branches) {
1184
+ if (!chunks[chunkIndex]) {
1185
+ chunks[chunkIndex] = [];
1186
+ }
1187
+ chunks[chunkIndex].push(branch);
1188
+ if (chunks[chunkIndex].length >= chunkSize) {
1189
+ chunkIndex = chunkIndex + 1;
1190
+ }
1191
+ }
1192
+ return chunks;
1193
+ }
1194
+ var branchDetailsQueryKey = (repository, branch = void 0) => {
1195
+ let branchName;
1196
+ if (!branch) {
1197
+ branchName = "_";
1198
+ } else {
1199
+ branchName = branch;
1200
+ }
1201
+ return [...repoQueryKey(repository), "branch-details", branchName];
1202
+ };
1203
+ var useBranchDetailsCollection = (repository, branches) => {
1204
+ var _a;
1205
+ const link = requiredLink(repository, "branchDetailsCollection");
1206
+ const chunks = chunkBranches(branches);
1207
+ const queryClient2 = useQueryClient6();
1208
+ const { data, isLoading, error, fetchNextPage } = useInfiniteQuery(branchDetailsQueryKey(repository), ({ pageParam = 0 }) => {
1209
+ var _a2;
1210
+ const encodedBranches = (_a2 = chunks[pageParam]) == null ? void 0 : _a2.map((b) => encodeURIComponent(b.name)).join("&branches=");
1211
+ return apiClient.get(concat(link, `?branches=${encodedBranches}`)).then((response) => response.json());
1212
+ }, {
1213
+ getNextPageParam: (lastPage, allPages) => {
1214
+ if (allPages.length >= chunks.length) {
1215
+ return void 0;
1216
+ }
1217
+ return allPages.length;
1218
+ },
1219
+ onSuccess: (newData) => {
1220
+ newData.pages.flatMap((d) => {
1221
+ var _a2;
1222
+ return (_a2 = d._embedded) == null ? void 0 : _a2.branchDetails;
1223
+ }).filter((d) => !!d).forEach((d) => queryClient2.setQueryData(branchDetailsQueryKey(repository, d.branchName), () => d));
1224
+ }
1225
+ });
1226
+ useEffect2(() => {
1227
+ fetchNextPage();
1228
+ }, [data, fetchNextPage]);
1229
+ return {
1230
+ data: (_a = data == null ? void 0 : data.pages) == null ? void 0 : _a.map((d) => {
1231
+ var _a2;
1232
+ return (_a2 = d._embedded) == null ? void 0 : _a2.branchDetails;
1233
+ }).flat(1),
1234
+ isLoading,
1235
+ error
1236
+ };
1237
+ };
1238
+ var useBranchDetails = (repository, branch) => {
1239
+ const link = branch._links.details.href;
1240
+ const queryKey = branchDetailsQueryKey(repository, branch.name);
1241
+ return useQuery7(queryKey, () => apiClient.get(link).then((response) => response.json()));
1242
+ };
1243
+ var createBranch = (link) => {
1244
+ return (branch) => {
1245
+ return apiClient.post(link, branch, "application/vnd.scmm-branchRequest+json;v=2").then((response) => {
1246
+ const location = response.headers.get("Location");
1247
+ if (!location) {
1248
+ throw new Error("Server does not return required Location header");
1249
+ }
1250
+ return apiClient.get(location);
1251
+ }).then((response) => response.json());
1252
+ };
1253
+ };
1254
+ var useCreateBranch = (repository) => {
1255
+ const queryClient2 = useQueryClient6();
1256
+ const link = requiredLink(repository, "branches");
1257
+ const { mutate, isLoading, error, data } = useMutation5(createBranch(link), {
1258
+ onSuccess: async (branch) => {
1259
+ queryClient2.setQueryData(branchQueryKey(repository, branch), branch);
1260
+ await queryClient2.invalidateQueries(repoQueryKey(repository, "branches"));
1261
+ }
1262
+ });
1263
+ return {
1264
+ create: (branch) => mutate(branch),
1265
+ isLoading,
1266
+ error,
1267
+ branch: data
1268
+ };
1269
+ };
1270
+ var useDeleteBranch = (repository) => {
1271
+ const queryClient2 = useQueryClient6();
1272
+ const { mutate, isLoading, error, data } = useMutation5((branch) => {
1273
+ const deleteUrl = branch._links.delete.href;
1274
+ return apiClient.delete(deleteUrl);
1275
+ }, {
1276
+ onSuccess: async (_, branch) => {
1277
+ queryClient2.removeQueries(branchQueryKey(repository, branch));
1278
+ await queryClient2.invalidateQueries(repoQueryKey(repository, "branches"));
1279
+ }
1280
+ });
1281
+ return {
1282
+ remove: (branch) => mutate(branch),
1283
+ isLoading,
1284
+ error,
1285
+ isDeleted: !!data
1286
+ };
1287
+ };
1288
+ var useDefaultBranch = (repository) => {
1289
+ const link = requiredLink(repository, "defaultBranch");
1290
+ return useQuery7(branchQueryKey(repository, "__default-branch"), () => apiClient.get(link).then((response) => response.json()));
1291
+ };
1292
+
1293
+ // src/changesets.ts
1294
+ import { useQuery as useQuery8, useQueryClient as useQueryClient7 } from "react-query";
1295
+ var changesetQueryKey = (repository, id) => {
1296
+ return repoQueryKey(repository, "changeset", id);
1297
+ };
1298
+ var useChangesets = (repository, request) => {
1299
+ const queryClient2 = useQueryClient7();
1300
+ let link;
1301
+ let branch = "_";
1302
+ if (request == null ? void 0 : request.branch) {
1303
+ link = requiredLink(request.branch, "history");
1304
+ branch = request.branch.name;
1305
+ } else {
1306
+ link = requiredLink(repository, "changesets");
1307
+ }
1308
+ if ((request == null ? void 0 : request.page) || (request == null ? void 0 : request.limit)) {
1309
+ if ((request == null ? void 0 : request.page) && (request == null ? void 0 : request.limit)) {
1310
+ link = `${link}?page=${request.page}&pageSize=${request.limit}`;
1311
+ } else if (request.page) {
1312
+ link = `${link}?page=${request.page}`;
1313
+ } else if (request.limit) {
1314
+ link = `${link}?pageSize=${request.limit}`;
1315
+ }
1316
+ }
1317
+ const key = branchQueryKey(repository, branch, "changesets", (request == null ? void 0 : request.page) || 0);
1318
+ return useQuery8(key, () => apiClient.get(link).then((response) => response.json()), {
1319
+ onSuccess: (changesetCollection) => {
1320
+ var _a;
1321
+ (_a = changesetCollection._embedded) == null ? void 0 : _a.changesets.forEach((changeset) => {
1322
+ queryClient2.setQueryData(changesetQueryKey(repository, changeset.id), changeset);
1323
+ });
1324
+ }
1325
+ });
1326
+ };
1327
+ var useChangeset = (repository, id) => {
1328
+ const changesetsLink = requiredLink(repository, "changesets");
1329
+ return useQuery8(changesetQueryKey(repository, id), () => apiClient.get(concat(changesetsLink, id)).then((response) => response.json()));
1330
+ };
1331
+
1332
+ // src/tags.ts
1333
+ import { useMutation as useMutation6, useQuery as useQuery9, useQueryClient as useQueryClient8 } from "react-query";
1334
+ var tagQueryKey = (repository, tag) => {
1335
+ return repoQueryKey(repository, "tag", tag);
1336
+ };
1337
+ var useTags = (repository) => {
1338
+ const link = requiredLink(repository, "tags");
1339
+ return useQuery9(repoQueryKey(repository, "tags"), () => apiClient.get(link).then((response) => response.json()));
1340
+ };
1341
+ var useTag = (repository, name) => {
1342
+ const link = requiredLink(repository, "tags");
1343
+ return useQuery9(tagQueryKey(repository, name), () => apiClient.get(concat(link, name)).then((response) => response.json()));
1344
+ };
1345
+ var invalidateCacheForTag = (queryClient2, repository, tag) => {
1346
+ return Promise.all([
1347
+ queryClient2.invalidateQueries(repoQueryKey(repository, "tags")),
1348
+ queryClient2.invalidateQueries(repoQueryKey(repository, "changesets")),
1349
+ queryClient2.invalidateQueries(repoQueryKey(repository, "changeset", tag.revision))
1350
+ ]);
1351
+ };
1352
+ var createTag = (changeset, link) => {
1353
+ return (name) => {
1354
+ return apiClient.post(link, {
1355
+ name,
1356
+ revision: changeset.id
1357
+ }).then((response) => {
1358
+ const location = response.headers.get("Location");
1359
+ if (!location) {
1360
+ throw new Error("Server does not return required Location header");
1361
+ }
1362
+ return apiClient.get(location);
1363
+ }).then((response) => response.json());
1364
+ };
1365
+ };
1366
+ var useCreateTag = (repository, changeset) => {
1367
+ const queryClient2 = useQueryClient8();
1368
+ const link = requiredLink(changeset, "tag");
1369
+ const { isLoading, error, mutate, data } = useMutation6(createTag(changeset, link), {
1370
+ onSuccess: async (tag) => {
1371
+ queryClient2.setQueryData(tagQueryKey(repository, tag.name), tag);
1372
+ await queryClient2.invalidateQueries(tagQueryKey(repository, tag.name));
1373
+ await invalidateCacheForTag(queryClient2, repository, tag);
1374
+ }
1375
+ });
1376
+ return {
1377
+ isLoading,
1378
+ error,
1379
+ create: (name) => mutate(name),
1380
+ tag: data
1381
+ };
1382
+ };
1383
+ var useDeleteTag = (repository) => {
1384
+ const queryClient2 = useQueryClient8();
1385
+ const { mutate, isLoading, error, data } = useMutation6((tag) => {
1386
+ const deleteUrl = tag._links.delete.href;
1387
+ return apiClient.delete(deleteUrl);
1388
+ }, {
1389
+ onSuccess: async (_, tag) => {
1390
+ queryClient2.removeQueries(tagQueryKey(repository, tag.name));
1391
+ await invalidateCacheForTag(queryClient2, repository, tag);
1392
+ }
1393
+ });
1394
+ return {
1395
+ remove: (tag) => mutate(tag),
1396
+ isLoading,
1397
+ error,
1398
+ isDeleted: !!data
1399
+ };
1400
+ };
1401
+
1402
+ // src/config.ts
1403
+ import { useMutation as useMutation7, useQuery as useQuery10, useQueryClient as useQueryClient9 } from "react-query";
1404
+ var useConfig = () => {
1405
+ const indexLink = useIndexLink("config");
1406
+ return useQuery10("config", () => apiClient.get(indexLink).then((response) => response.json()), {
1407
+ enabled: !!indexLink
1408
+ });
1409
+ };
1410
+ var useUpdateConfig = () => {
1411
+ const queryClient2 = useQueryClient9();
1412
+ const { mutate, isLoading, error, data, reset: reset2 } = useMutation7((config) => {
1413
+ const updateUrl = requiredLink(config, "update");
1414
+ return apiClient.put(updateUrl, config, "application/vnd.scmm-config+json;v=2");
1415
+ }, {
1416
+ onSuccess: async () => {
1417
+ await queryClient2.invalidateQueries("config");
1418
+ await queryClient2.invalidateQueries("index");
1419
+ await queryClient2.invalidateQueries("pluginCenterAuth");
1420
+ }
1421
+ });
1422
+ return {
1423
+ update: (config) => mutate(config),
1424
+ isLoading,
1425
+ error,
1426
+ isUpdated: !!data,
1427
+ reset: reset2
1428
+ };
1429
+ };
1430
+
1431
+ // src/admin.ts
1432
+ import { useQuery as useQuery11 } from "react-query";
1433
+ var useUpdateInfo = () => {
1434
+ const indexLink = useIndexLink("updateInfo");
1435
+ return useQuery11("updateInfo", () => {
1436
+ if (!indexLink) {
1437
+ throw new Error("could not find index data");
1438
+ }
1439
+ return apiClient.get(indexLink).then((response) => response.status === 204 ? null : response.json());
1440
+ }, { enabled: !!indexLink });
1441
+ };
1442
+
1443
+ // src/plugins.ts
1444
+ import { isPluginCollection } from "@scm-manager/ui-types";
1445
+ import { useMutation as useMutation8, useQuery as useQuery12, useQueryClient as useQueryClient10 } from "react-query";
1446
+ var waitForRestartAfter = (promise, { initialDelay = 1e3, timeout = 500 } = {}) => {
1447
+ const endTime = Number(new Date()) + 4 * 60 * 1e3;
1448
+ let started = false;
1449
+ const executor = (data) => (resolve, reject) => {
1450
+ if (!started) {
1451
+ started = true;
1452
+ setTimeout(executor(data), initialDelay, resolve, reject);
1453
+ } else {
1454
+ apiClient.get("").then(() => resolve(data)).catch(() => {
1455
+ if (Number(new Date()) < endTime) {
1456
+ setTimeout(executor(data), timeout, resolve, reject);
1457
+ } else {
1458
+ reject(new Error("timeout reached"));
1459
+ }
1460
+ });
1461
+ }
1462
+ };
1463
+ return promise.catch((err) => {
1464
+ if (err instanceof BadGatewayError) {
1465
+ return "ok";
1466
+ }
1467
+ throw err;
1468
+ }).then((data) => new Promise(executor(data)));
1469
+ };
1470
+ var useAvailablePlugins = ({ enabled } = {}) => {
1471
+ const indexLink = useRequiredIndexLink("availablePlugins");
1472
+ return useQuery12(["plugins", "available"], () => apiClient.get(indexLink).then((response) => response.json()), {
1473
+ enabled,
1474
+ retry: 3
1475
+ });
1476
+ };
1477
+ var useInstalledPlugins = ({ enabled } = {}) => {
1478
+ const indexLink = useRequiredIndexLink("installedPlugins");
1479
+ return useQuery12(["plugins", "installed"], () => apiClient.get(indexLink).then((response) => response.json()), {
1480
+ enabled,
1481
+ retry: 3
1482
+ });
1483
+ };
1484
+ var usePendingPlugins = () => {
1485
+ const indexLink = useIndexLink("pendingPlugins");
1486
+ return useQuery12(["plugins", "pending"], () => apiClient.get(indexLink).then((response) => response.json()), {
1487
+ enabled: !!indexLink,
1488
+ retry: 3
1489
+ });
1490
+ };
1491
+ var linkWithRestart = (link, restart) => {
1492
+ if (restart) {
1493
+ return link + "WithRestart";
1494
+ }
1495
+ return link;
1496
+ };
1497
+ var useInstallPlugin = () => {
1498
+ const queryClient2 = useQueryClient10();
1499
+ const { mutate, isLoading, error, data } = useMutation8((_a) => {
1500
+ var { plugin, restartOptions: _b } = _a, _c = _b, { restart } = _c, waitForRestartOptions = __objRest(_c, ["restart"]);
1501
+ const promise = apiClient.post(requiredLink(plugin, linkWithRestart("install", restart)));
1502
+ if (restart) {
1503
+ return waitForRestartAfter(promise, waitForRestartOptions);
1504
+ }
1505
+ return promise;
1506
+ }, {
1507
+ onSuccess: () => queryClient2.invalidateQueries("plugins")
1508
+ });
1509
+ return {
1510
+ install: (plugin, restartOptions = {}) => mutate({
1511
+ plugin,
1512
+ restartOptions
1513
+ }),
1514
+ isLoading,
1515
+ error,
1516
+ data,
1517
+ isInstalled: !!data
1518
+ };
1519
+ };
1520
+ var useUninstallPlugin = () => {
1521
+ const queryClient2 = useQueryClient10();
1522
+ const { mutate, isLoading, error, data } = useMutation8((_a) => {
1523
+ var { plugin, restartOptions: _b } = _a, _c = _b, { restart } = _c, waitForRestartOptions = __objRest(_c, ["restart"]);
1524
+ const promise = apiClient.post(requiredLink(plugin, linkWithRestart("uninstall", restart)));
1525
+ if (restart) {
1526
+ return waitForRestartAfter(promise, waitForRestartOptions);
1527
+ }
1528
+ return promise;
1529
+ }, {
1530
+ onSuccess: () => queryClient2.invalidateQueries("plugins")
1531
+ });
1532
+ return {
1533
+ uninstall: (plugin, restartOptions = {}) => mutate({
1534
+ plugin,
1535
+ restartOptions
1536
+ }),
1537
+ isLoading,
1538
+ error,
1539
+ isUninstalled: !!data
1540
+ };
1541
+ };
1542
+ var useUpdatePlugins = () => {
1543
+ const queryClient2 = useQueryClient10();
1544
+ const { mutate, isLoading, error, data } = useMutation8((_a) => {
1545
+ var { plugins, restartOptions: _b } = _a, _c = _b, { restart } = _c, waitForRestartOptions = __objRest(_c, ["restart"]);
1546
+ const isCollection = isPluginCollection(plugins);
1547
+ const promise = apiClient.post(requiredLink(plugins, isCollection ? "update" : linkWithRestart("update", restart)));
1548
+ if (restart && !isCollection) {
1549
+ return waitForRestartAfter(promise, waitForRestartOptions);
1550
+ }
1551
+ return promise;
1552
+ }, {
1553
+ onSuccess: () => queryClient2.invalidateQueries("plugins")
1554
+ });
1555
+ return {
1556
+ update: (plugin, restartOptions = {}) => mutate({
1557
+ plugins: plugin,
1558
+ restartOptions
1559
+ }),
1560
+ isLoading,
1561
+ error,
1562
+ isUpdated: !!data
1563
+ };
1564
+ };
1565
+ var useExecutePendingPlugins = () => {
1566
+ const queryClient2 = useQueryClient10();
1567
+ const { mutate, isLoading, error, data } = useMutation8(({ pending, restartOptions }) => waitForRestartAfter(apiClient.post(requiredLink(pending, "execute")), restartOptions), {
1568
+ onSuccess: () => queryClient2.invalidateQueries("plugins")
1569
+ });
1570
+ return {
1571
+ update: (pending, restartOptions = {}) => mutate({ pending, restartOptions }),
1572
+ isLoading,
1573
+ error,
1574
+ isExecuted: !!data
1575
+ };
1576
+ };
1577
+ var useCancelPendingPlugins = () => {
1578
+ const queryClient2 = useQueryClient10();
1579
+ const { mutate, isLoading, error, data } = useMutation8((pending) => apiClient.post(requiredLink(pending, "cancel")), {
1580
+ onSuccess: () => queryClient2.invalidateQueries("plugins")
1581
+ });
1582
+ return {
1583
+ update: (pending) => mutate(pending),
1584
+ isLoading,
1585
+ error,
1586
+ isCancelled: !!data
1587
+ };
1588
+ };
1589
+
1590
+ // src/repository-roles.ts
1591
+ import { useMutation as useMutation9, useQuery as useQuery13, useQueryClient as useQueryClient11 } from "react-query";
1592
+ var useRepositoryRoles = (request) => {
1593
+ const queryClient2 = useQueryClient11();
1594
+ const indexLink = useRequiredIndexLink("repositoryRoles");
1595
+ const queryParams = {};
1596
+ if (request == null ? void 0 : request.page) {
1597
+ queryParams.page = request.page.toString();
1598
+ }
1599
+ return useQuery13(["repositoryRoles", (request == null ? void 0 : request.page) || 0], () => apiClient.get(`${indexLink}?${createQueryString(queryParams)}`).then((response) => response.json()), {
1600
+ onSuccess: (repositoryRoles) => {
1601
+ var _a;
1602
+ (_a = repositoryRoles._embedded) == null ? void 0 : _a.repositoryRoles.forEach((repositoryRole) => queryClient2.setQueryData(["repositoryRole", repositoryRole.name], repositoryRole));
1603
+ }
1604
+ });
1605
+ };
1606
+ var useRepositoryRole = (name) => {
1607
+ const indexLink = useRequiredIndexLink("repositoryRoles");
1608
+ return useQuery13(["repositoryRole", name], () => apiClient.get(concat(indexLink, name)).then((response) => response.json()));
1609
+ };
1610
+ var createRepositoryRole = (link) => {
1611
+ return (repositoryRole) => {
1612
+ return apiClient.post(link, repositoryRole, "application/vnd.scmm-repositoryRole+json;v=2").then((response) => {
1613
+ const location = response.headers.get("Location");
1614
+ if (!location) {
1615
+ throw new Error("Server does not return required Location header");
1616
+ }
1617
+ return apiClient.get(location);
1618
+ }).then((response) => response.json());
1619
+ };
1620
+ };
1621
+ var useCreateRepositoryRole = () => {
1622
+ const queryClient2 = useQueryClient11();
1623
+ const link = useRequiredIndexLink("repositoryRoles");
1624
+ const { mutate, data, isLoading, error } = useMutation9(createRepositoryRole(link), {
1625
+ onSuccess: (repositoryRole) => {
1626
+ queryClient2.setQueryData(["repositoryRole", repositoryRole.name], repositoryRole);
1627
+ return queryClient2.invalidateQueries(["repositoryRoles"]);
1628
+ }
1629
+ });
1630
+ return {
1631
+ create: (repositoryRole) => mutate(repositoryRole),
1632
+ isLoading,
1633
+ error,
1634
+ repositoryRole: data
1635
+ };
1636
+ };
1637
+ var useUpdateRepositoryRole = () => {
1638
+ const queryClient2 = useQueryClient11();
1639
+ const { mutate, isLoading, error, data } = useMutation9((repositoryRole) => {
1640
+ const updateUrl = requiredLink(repositoryRole, "update");
1641
+ return apiClient.put(updateUrl, repositoryRole, "application/vnd.scmm-repositoryRole+json;v=2");
1642
+ }, {
1643
+ onSuccess: async (_, repositoryRole) => {
1644
+ await queryClient2.invalidateQueries(["repositoryRole", repositoryRole.name]);
1645
+ await queryClient2.invalidateQueries(["repositoryRoles"]);
1646
+ }
1647
+ });
1648
+ return {
1649
+ update: (repositoryRole) => mutate(repositoryRole),
1650
+ isLoading,
1651
+ error,
1652
+ isUpdated: !!data
1653
+ };
1654
+ };
1655
+ var useDeleteRepositoryRole = () => {
1656
+ const queryClient2 = useQueryClient11();
1657
+ const { mutate, isLoading, error, data } = useMutation9((repositoryRole) => {
1658
+ const deleteUrl = requiredLink(repositoryRole, "delete");
1659
+ return apiClient.delete(deleteUrl);
1660
+ }, {
1661
+ onSuccess: async (_, name) => {
1662
+ await queryClient2.removeQueries(["repositoryRole", name]);
1663
+ await queryClient2.invalidateQueries(["repositoryRoles"]);
1664
+ }
1665
+ });
1666
+ return {
1667
+ remove: (repositoryRole) => mutate(repositoryRole),
1668
+ isLoading,
1669
+ error,
1670
+ isDeleted: !!data
1671
+ };
1672
+ };
1673
+
1674
+ // src/permissions.ts
1675
+ import { useMutation as useMutation10, useQuery as useQuery14, useQueryClient as useQueryClient12 } from "react-query";
1676
+ var useRepositoryVerbs = () => {
1677
+ return useIndexJsonResource("repositoryVerbs");
1678
+ };
1679
+ var useAvailablePermissions = () => {
1680
+ var _a;
1681
+ const roles = useRepositoryRoles();
1682
+ const verbs = useRepositoryVerbs();
1683
+ let data;
1684
+ if (roles.data && verbs.data) {
1685
+ data = {
1686
+ repositoryVerbs: verbs.data.verbs,
1687
+ repositoryRoles: ((_a = roles.data._embedded) == null ? void 0 : _a.repositoryRoles) || []
1688
+ };
1689
+ }
1690
+ return {
1691
+ isLoading: roles.isLoading || verbs.isLoading,
1692
+ error: roles.error || verbs.error,
1693
+ data
1694
+ };
1695
+ };
1696
+ var isRepository = (namespaceOrRepository) => {
1697
+ return namespaceOrRepository.name !== void 0;
1698
+ };
1699
+ var createQueryKey = (namespaceOrRepository) => {
1700
+ if (isRepository(namespaceOrRepository)) {
1701
+ return repoQueryKey(namespaceOrRepository, "permissions");
1702
+ } else {
1703
+ return ["namespace", namespaceOrRepository.namespace, "permissions"];
1704
+ }
1705
+ };
1706
+ var usePermissions = (namespaceOrRepository) => {
1707
+ const link = requiredLink(namespaceOrRepository, "permissions");
1708
+ const queryKey = createQueryKey(namespaceOrRepository);
1709
+ return useQuery14(queryKey, () => apiClient.get(link).then((response) => response.json()));
1710
+ };
1711
+ var createPermission = (link) => {
1712
+ return (permission) => {
1713
+ return apiClient.post(link, permission, "application/vnd.scmm-repositoryPermission+json").then((response) => {
1714
+ const location = response.headers.get("Location");
1715
+ if (!location) {
1716
+ throw new Error("Server does not return required Location header");
1717
+ }
1718
+ return apiClient.get(location);
1719
+ }).then((response) => response.json());
1720
+ };
1721
+ };
1722
+ var useCreatePermission = (namespaceOrRepository) => {
1723
+ const queryClient2 = useQueryClient12();
1724
+ const link = requiredLink(namespaceOrRepository, "permissions");
1725
+ const { isLoading, error, mutate, data } = useMutation10(createPermission(link), {
1726
+ onSuccess: () => {
1727
+ const queryKey = createQueryKey(namespaceOrRepository);
1728
+ return queryClient2.invalidateQueries(queryKey);
1729
+ }
1730
+ });
1731
+ return {
1732
+ isLoading,
1733
+ error,
1734
+ create: (permission) => mutate(permission),
1735
+ permission: data
1736
+ };
1737
+ };
1738
+ var useUpdatePermission = (namespaceOrRepository) => {
1739
+ const queryClient2 = useQueryClient12();
1740
+ const { isLoading, error, mutate, data } = useMutation10((permission) => {
1741
+ const link = requiredLink(permission, "update");
1742
+ return apiClient.put(link, permission, "application/vnd.scmm-repositoryPermission+json");
1743
+ }, {
1744
+ onSuccess: () => {
1745
+ const queryKey = createQueryKey(namespaceOrRepository);
1746
+ return queryClient2.invalidateQueries(queryKey);
1747
+ }
1748
+ });
1749
+ return {
1750
+ isLoading,
1751
+ error,
1752
+ update: (permission) => mutate(permission),
1753
+ isUpdated: !!data
1754
+ };
1755
+ };
1756
+ var useDeletePermission = (namespaceOrRepository) => {
1757
+ const queryClient2 = useQueryClient12();
1758
+ const { isLoading, error, mutate, data } = useMutation10((permission) => {
1759
+ const link = requiredLink(permission, "delete");
1760
+ return apiClient.delete(link);
1761
+ }, {
1762
+ onSuccess: () => {
1763
+ const queryKey = createQueryKey(namespaceOrRepository);
1764
+ return queryClient2.invalidateQueries(queryKey);
1765
+ }
1766
+ });
1767
+ return {
1768
+ isLoading,
1769
+ error,
1770
+ remove: (permission) => mutate(permission),
1771
+ isDeleted: !!data
1772
+ };
1773
+ };
1774
+ var userPermissionsKey = (user) => ["user", user.name, "permissions"];
1775
+ var groupPermissionsKey = (group) => ["group", group.name, "permissions"];
1776
+ var useGroupPermissions = (group) => useJsonResource(group, "permissions", groupPermissionsKey(group));
1777
+ var useUserPermissions = (user) => useJsonResource(user, "permissions", userPermissionsKey(user));
1778
+ var useAvailableGlobalPermissions = () => useIndexJsonResource("permissions");
1779
+ var useSetEntityPermissions = (permissionCollection, key) => {
1780
+ const queryClient2 = useQueryClient12();
1781
+ const url = permissionCollection ? objectLink(permissionCollection, "overwrite") : null;
1782
+ const { isLoading, error, mutate, data } = useMutation10((permissions) => apiClient.put(url, {
1783
+ permissions
1784
+ }, "application/vnd.scmm-permissionCollection+json;v=2"), {
1785
+ onSuccess: () => queryClient2.invalidateQueries(key)
1786
+ });
1787
+ const setPermissions = (permissions) => mutate(permissions);
1788
+ return {
1789
+ isLoading,
1790
+ error,
1791
+ setPermissions: url ? setPermissions : void 0,
1792
+ isUpdated: !!data
1793
+ };
1794
+ };
1795
+ var useSetUserPermissions = (user, permissions) => useSetEntityPermissions(permissions, userPermissionsKey(user));
1796
+ var useSetGroupPermissions = (group, permissions) => useSetEntityPermissions(permissions, groupPermissionsKey(group));
1797
+
1798
+ // src/sources.ts
1799
+ import { useInfiniteQuery as useInfiniteQuery2 } from "react-query";
1800
+ import { useEffect as useEffect3 } from "react";
1801
+ var UseSourcesDefaultOptions = {
1802
+ enabled: true,
1803
+ refetchPartialInterval: 3e3,
1804
+ collapse: true
1805
+ };
1806
+ var useSources = (repository, opts = UseSourcesDefaultOptions) => {
1807
+ const options = __spreadValues(__spreadValues({}, UseSourcesDefaultOptions), opts);
1808
+ const link = createSourcesLink(repository, options);
1809
+ const { isLoading, error, data, isFetchingNextPage, fetchNextPage, refetch } = useInfiniteQuery2(repoQueryKey(repository, "sources", options.revision || "", options.path || "", options.collapse ? "collapse" : ""), ({ pageParam }) => {
1810
+ return apiClient.get(pageParam || link).then((response) => response.json());
1811
+ }, {
1812
+ enabled: options.enabled,
1813
+ getNextPageParam: (lastPage) => {
1814
+ var _a;
1815
+ return (_a = lastPage._links.proceed) == null ? void 0 : _a.href;
1816
+ }
1817
+ });
1818
+ const file = merge(data == null ? void 0 : data.pages);
1819
+ useEffect3(() => {
1820
+ const intervalId = setInterval(() => {
1821
+ if (isPartial(file)) {
1822
+ refetch({
1823
+ throwOnError: true
1824
+ });
1825
+ }
1826
+ }, options.refetchPartialInterval);
1827
+ return () => clearInterval(intervalId);
1828
+ }, [options.refetchPartialInterval, file, refetch]);
1829
+ return {
1830
+ isLoading,
1831
+ error,
1832
+ data: file,
1833
+ isFetchingNextPage,
1834
+ fetchNextPage: () => {
1835
+ fetchNextPage();
1836
+ }
1837
+ };
1838
+ };
1839
+ var createSourcesLink = (repository, options) => {
1840
+ let link = requiredLink(repository, "sources");
1841
+ if (options.revision) {
1842
+ link = concat(link, encodeURIComponent(options.revision));
1843
+ if (options.path) {
1844
+ link = concat(link, options.path);
1845
+ }
1846
+ }
1847
+ if (options.collapse) {
1848
+ return `${link}?${createQueryString({ collapse: "true" })}`;
1849
+ }
1850
+ return link;
1851
+ };
1852
+ var merge = (files) => {
1853
+ var _a;
1854
+ if (!files || files.length === 0) {
1855
+ return;
1856
+ }
1857
+ const children = [];
1858
+ for (const page of files) {
1859
+ children.push(...((_a = page._embedded) == null ? void 0 : _a.children) || []);
1860
+ }
1861
+ const lastPage = files[files.length - 1];
1862
+ return __spreadProps(__spreadValues({}, lastPage), {
1863
+ _embedded: __spreadProps(__spreadValues({}, lastPage._embedded), {
1864
+ children
1865
+ })
1866
+ });
1867
+ };
1868
+ var isFilePartial = (f) => {
1869
+ return f.partialResult && !f.computationAborted;
1870
+ };
1871
+ var isPartial = (file) => {
1872
+ var _a, _b;
1873
+ if (!file) {
1874
+ return false;
1875
+ }
1876
+ if (isFilePartial(file)) {
1877
+ return true;
1878
+ }
1879
+ return (_b = (_a = file._embedded) == null ? void 0 : _a.children) == null ? void 0 : _b.some(isFilePartial);
1880
+ };
1881
+
1882
+ // src/import.ts
1883
+ import { useMutation as useMutation11, useQuery as useQuery15 } from "react-query";
1884
+ var useImportLog = (logId) => {
1885
+ const link = useRequiredIndexLink("importLog").replace("{logId}", logId);
1886
+ return useQuery15(["importLog", logId], () => apiClient.get(link).then((response) => response.text()));
1887
+ };
1888
+ var useImportRepositoryFromUrl = (repositoryType) => {
1889
+ const url = requiredLink(repositoryType, "import", "url");
1890
+ const { isLoading, error, data, mutate } = useMutation11((repo) => apiClient.post(url, repo, "application/vnd.scmm-repository+json;v=2").then(fetchResourceFromLocationHeader).then(getResponseJson));
1891
+ return {
1892
+ isLoading,
1893
+ error,
1894
+ importRepositoryFromUrl: (repository) => mutate(repository),
1895
+ importedRepository: data
1896
+ };
1897
+ };
1898
+ var importRepository = (url, repository, file, password) => {
1899
+ return apiClient.postBinary(url, (formData) => {
1900
+ formData.append("bundle", file, file.name);
1901
+ formData.append("repository", JSON.stringify(__spreadProps(__spreadValues({}, repository), { password })));
1902
+ }).then(fetchResourceFromLocationHeader).then(getResponseJson);
1903
+ };
1904
+ var useImportRepositoryFromBundle = (repositoryType) => {
1905
+ const url = requiredLink(repositoryType, "import", "bundle");
1906
+ const { isLoading, error, data, mutate } = useMutation11(({ repository, file, compressed, password }) => importRepository(compressed ? url + "?compressed=true" : url, repository, file, password));
1907
+ return {
1908
+ isLoading,
1909
+ error,
1910
+ importRepositoryFromBundle: (repository, file, compressed, password) => mutate({
1911
+ repository,
1912
+ file,
1913
+ compressed,
1914
+ password
1915
+ }),
1916
+ importedRepository: data
1917
+ };
1918
+ };
1919
+ var useImportFullRepository = (repositoryType) => {
1920
+ const { isLoading, error, data, mutate } = useMutation11(({ repository, file, password }) => importRepository(requiredLink(repositoryType, "import", "fullImport"), repository, file, password));
1921
+ return {
1922
+ isLoading,
1923
+ error,
1924
+ importFullRepository: (repository, file, password) => mutate({
1925
+ repository,
1926
+ file,
1927
+ password
1928
+ }),
1929
+ importedRepository: data
1930
+ };
1931
+ };
1932
+
1933
+ // src/diff.ts
1934
+ import parser from "gitdiff-parser";
1935
+ import { useInfiniteQuery as useInfiniteQuery3 } from "react-query";
1936
+ var defaultOptions = {
1937
+ refetchOnWindowFocus: true
1938
+ };
1939
+ var useDiff = (link, options = defaultOptions) => {
1940
+ let initialLink = link;
1941
+ if (options.limit) {
1942
+ const separator = initialLink.includes("?") ? "&" : "?";
1943
+ initialLink = `${initialLink}${separator}limit=${options.limit}`;
1944
+ }
1945
+ const { isLoading, error, data, isFetchingNextPage, fetchNextPage } = useInfiniteQuery3(["link", link], ({ pageParam }) => {
1946
+ return apiClient.get(pageParam || initialLink).then((response) => {
1947
+ const contentType = response.headers.get("Content-Type");
1948
+ if (contentType && contentType.toLowerCase() === "application/vnd.scmm-diffparsed+json;v=2") {
1949
+ return response.json();
1950
+ } else {
1951
+ return response.text().then(parser.parse).then((parsedGit) => {
1952
+ return {
1953
+ files: parsedGit,
1954
+ partial: false,
1955
+ _links: {}
1956
+ };
1957
+ });
1958
+ }
1959
+ });
1960
+ }, {
1961
+ getNextPageParam: (lastPage) => {
1962
+ var _a;
1963
+ return (_a = lastPage._links.next) == null ? void 0 : _a.href;
1964
+ },
1965
+ refetchOnWindowFocus: options.refetchOnWindowFocus
1966
+ });
1967
+ return {
1968
+ isLoading,
1969
+ error,
1970
+ isFetchingNextPage,
1971
+ fetchNextPage: () => {
1972
+ fetchNextPage();
1973
+ },
1974
+ data: merge2(data == null ? void 0 : data.pages)
1975
+ };
1976
+ };
1977
+ var merge2 = (diffs) => {
1978
+ if (!diffs || diffs.length === 0) {
1979
+ return;
1980
+ }
1981
+ const joinedFiles = diffs.flatMap((diff) => diff.files);
1982
+ return __spreadProps(__spreadValues({}, diffs[diffs.length - 1]), {
1983
+ files: joinedFiles
1984
+ });
1985
+ };
1986
+
1987
+ // src/notifications.ts
1988
+ import { useMutation as useMutation12, useQuery as useQuery16, useQueryClient as useQueryClient13 } from "react-query";
1989
+ import { useCallback as useCallback2, useEffect as useEffect4, useState as useState2 } from "react";
1990
+ var useNotifications = () => {
1991
+ var _a;
1992
+ const { data: me } = useMe();
1993
+ const link = (_a = me == null ? void 0 : me._links["notifications"]) == null ? void 0 : _a.href;
1994
+ const { data, error, isLoading, refetch } = useQuery16("notifications", () => apiClient.get(link).then((response) => response.json()), {
1995
+ enabled: !!link
1996
+ });
1997
+ const memoizedRefetch = useCallback2(() => {
1998
+ return refetch().then((r) => r.data);
1999
+ }, [refetch]);
2000
+ return {
2001
+ data,
2002
+ error,
2003
+ isLoading,
2004
+ refetch: memoizedRefetch
2005
+ };
2006
+ };
2007
+ var useDismissNotification = (notification) => {
2008
+ const queryClient2 = useQueryClient13();
2009
+ const link = requiredLink(notification, "dismiss");
2010
+ const { data, isLoading, error, mutate } = useMutation12(() => apiClient.delete(link), {
2011
+ onSuccess: () => {
2012
+ queryClient2.invalidateQueries("notifications");
2013
+ }
2014
+ });
2015
+ return {
2016
+ isLoading,
2017
+ error,
2018
+ dismiss: () => mutate(),
2019
+ isCleared: !!data
2020
+ };
2021
+ };
2022
+ var useClearNotifications = (notificationCollection) => {
2023
+ const queryClient2 = useQueryClient13();
2024
+ const link = requiredLink(notificationCollection, "clear");
2025
+ const { data, isLoading, error, mutate } = useMutation12(() => apiClient.delete(link), {
2026
+ onSuccess: () => {
2027
+ queryClient2.invalidateQueries("notifications");
2028
+ }
2029
+ });
2030
+ return {
2031
+ isLoading,
2032
+ error,
2033
+ clear: () => mutate(),
2034
+ isCleared: !!data
2035
+ };
2036
+ };
2037
+ var isEqual = (left, right) => {
2038
+ return left === right || left.message === right.message && left.createdAt === right.createdAt;
2039
+ };
2040
+ var useNotificationSubscription = (refetch, notificationCollection) => {
2041
+ var _a;
2042
+ const [notifications, setNotifications] = useState2([]);
2043
+ const [disconnectedAt, setDisconnectedAt] = useState2();
2044
+ const link = (_a = notificationCollection == null ? void 0 : notificationCollection._links.subscribe) == null ? void 0 : _a.href;
2045
+ const onVisible = useCallback2(() => {
2046
+ refetch().then((collection) => {
2047
+ var _a2;
2048
+ if (collection) {
2049
+ const newNotifications = (_a2 = collection._embedded) == null ? void 0 : _a2.notifications.filter((n) => {
2050
+ return disconnectedAt && disconnectedAt < new Date(n.createdAt);
2051
+ });
2052
+ if (newNotifications && newNotifications.length > 0) {
2053
+ setNotifications((previous) => [...previous, ...newNotifications]);
2054
+ }
2055
+ setDisconnectedAt(void 0);
2056
+ }
2057
+ });
2058
+ }, [disconnectedAt, refetch]);
2059
+ const onHide = useCallback2(() => {
2060
+ setDisconnectedAt(new Date());
2061
+ }, []);
2062
+ const received = useCallback2((notification) => {
2063
+ setNotifications((previous) => [...previous, notification]);
2064
+ refetch();
2065
+ }, [refetch]);
2066
+ useEffect4(() => {
2067
+ if (link) {
2068
+ let cancel;
2069
+ const disconnect = () => {
2070
+ if (cancel) {
2071
+ cancel();
2072
+ }
2073
+ };
2074
+ const connect = () => {
2075
+ disconnect();
2076
+ cancel = apiClient.subscribe(link, {
2077
+ notification: (event) => {
2078
+ received(JSON.parse(event.data));
2079
+ }
2080
+ });
2081
+ };
2082
+ const handleVisibilityChange = () => {
2083
+ if (document.visibilityState === "visible") {
2084
+ onVisible();
2085
+ } else {
2086
+ onHide();
2087
+ }
2088
+ };
2089
+ if (document.visibilityState === "visible") {
2090
+ connect();
2091
+ }
2092
+ document.addEventListener("visibilitychange", handleVisibilityChange);
2093
+ return () => {
2094
+ disconnect();
2095
+ document.removeEventListener("visibilitychange", handleVisibilityChange);
2096
+ };
2097
+ }
2098
+ }, [link, onVisible, onHide, received]);
2099
+ const remove = useCallback2((notification) => {
2100
+ setNotifications((oldNotifications) => [...oldNotifications.filter((n) => !isEqual(n, notification))]);
2101
+ }, [setNotifications]);
2102
+ const clear = useCallback2(() => {
2103
+ setNotifications([]);
2104
+ }, [setNotifications]);
2105
+ return {
2106
+ notifications,
2107
+ remove,
2108
+ clear
2109
+ };
2110
+ };
2111
+
2112
+ // src/alerts.ts
2113
+ import { useQuery as useQuery17 } from "react-query";
2114
+ var alertsFromStorage = () => {
2115
+ const item = localStorage.getItem("alerts");
2116
+ if (item) {
2117
+ return JSON.parse(item);
2118
+ }
2119
+ };
2120
+ var fetchAlerts = (request) => {
2121
+ var _a;
2122
+ const url = (_a = request._links["alerts"]) == null ? void 0 : _a.href;
2123
+ if (!url) {
2124
+ throw new Error("no alerts link defined");
2125
+ }
2126
+ return fetch(url, {
2127
+ method: "POST",
2128
+ headers: {
2129
+ "Content-Type": "application/json"
2130
+ },
2131
+ body: JSON.stringify(request.body)
2132
+ }).then((response) => {
2133
+ if (!response.ok) {
2134
+ throw new Error("Failed to fetch alerts");
2135
+ }
2136
+ return response;
2137
+ }).then((response) => response.json()).then((data) => {
2138
+ const storageItem = __spreadProps(__spreadValues({}, data), {
2139
+ checksum: request.checksum
2140
+ });
2141
+ localStorage.setItem("alerts", JSON.stringify(storageItem));
2142
+ return data;
2143
+ });
2144
+ };
2145
+ var restoreOrFetch = (request) => {
2146
+ const storedAlerts = alertsFromStorage();
2147
+ if (!storedAlerts || storedAlerts.checksum !== request.checksum) {
2148
+ return fetchAlerts(request);
2149
+ }
2150
+ return Promise.resolve(storedAlerts);
2151
+ };
2152
+ var useAlerts = () => {
2153
+ const link = useIndexLink("alerts");
2154
+ const { data, error, isLoading } = useQuery17("alerts", () => {
2155
+ if (!link) {
2156
+ throw new Error("Could not find alert link");
2157
+ }
2158
+ return apiClient.get(link).then((response) => response.json()).then(restoreOrFetch);
2159
+ }, {
2160
+ enabled: !!link,
2161
+ staleTime: Infinity
2162
+ });
2163
+ return {
2164
+ data,
2165
+ error,
2166
+ isLoading
2167
+ };
2168
+ };
2169
+
2170
+ // src/configLink.ts
2171
+ import { useMutation as useMutation13, useQuery as useQuery18, useQueryClient as useQueryClient14 } from "react-query";
2172
+ import { useCallback as useCallback3 } from "react";
2173
+ var useConfigLink = (link) => {
2174
+ const queryClient2 = useQueryClient14();
2175
+ const queryKey = ["configLink", link];
2176
+ const { isLoading, error, data } = useQuery18(queryKey, () => apiClient.get(link).then((response) => {
2177
+ const contentType = response.headers.get("Content-Type") || "application/json";
2178
+ return response.json().then((configuration) => ({ configuration, contentType }));
2179
+ }));
2180
+ const {
2181
+ isLoading: isUpdating,
2182
+ error: mutationError,
2183
+ mutate,
2184
+ data: updateResponse
2185
+ } = useMutation13((vars) => apiClient.put(vars.link, vars.configuration, vars.contentType), {
2186
+ onSuccess: async () => {
2187
+ await queryClient2.invalidateQueries(queryKey);
2188
+ }
2189
+ });
2190
+ const isReadOnly = !(data == null ? void 0 : data.configuration._links.update);
2191
+ const update = useCallback3((configuration) => {
2192
+ if (data && !isReadOnly) {
2193
+ mutate({
2194
+ configuration,
2195
+ contentType: data.contentType,
2196
+ link: data.configuration._links.update.href
2197
+ });
2198
+ }
2199
+ }, [mutate, data, isReadOnly]);
2200
+ return {
2201
+ isLoading,
2202
+ isUpdating,
2203
+ isReadOnly,
2204
+ error: error || mutationError,
2205
+ initialConfiguration: data == null ? void 0 : data.configuration,
2206
+ update,
2207
+ isUpdated: !!updateResponse
2208
+ };
2209
+ };
2210
+
2211
+ // src/apiKeys.ts
2212
+ import { useMutation as useMutation14, useQuery as useQuery19, useQueryClient as useQueryClient15 } from "react-query";
2213
+ var CONTENT_TYPE_API_KEY = "application/vnd.scmm-apiKey+json;v=2";
2214
+ var useApiKeys = (user) => useQuery19(["user", user.name, "apiKeys"], () => apiClient.get(requiredLink(user, "apiKeys")).then((r) => r.json()));
2215
+ var createApiKey = (link) => async (key) => {
2216
+ const creationResponse = await apiClient.post(link, key, CONTENT_TYPE_API_KEY);
2217
+ const location = creationResponse.headers.get("Location");
2218
+ if (!location) {
2219
+ throw new Error("Server does not return required Location header");
2220
+ }
2221
+ const locationResponse = await apiClient.get(location);
2222
+ const [apiKey, token] = await Promise.all([locationResponse.json(), creationResponse.text()]);
2223
+ return __spreadProps(__spreadValues({}, apiKey), { token });
2224
+ };
2225
+ var useCreateApiKey = (user, apiKeys) => {
2226
+ const queryClient2 = useQueryClient15();
2227
+ const { mutate, data, isLoading, error, reset: reset2 } = useMutation14(createApiKey(requiredLink(apiKeys, "create")), {
2228
+ onSuccess: () => queryClient2.invalidateQueries(["user", user.name, "apiKeys"])
2229
+ });
2230
+ return {
2231
+ create: (key) => mutate(key),
2232
+ isLoading,
2233
+ error,
2234
+ apiKey: data,
2235
+ reset: reset2
2236
+ };
2237
+ };
2238
+ var useDeleteApiKey = (user) => {
2239
+ const queryClient2 = useQueryClient15();
2240
+ const { mutate, isLoading, error, data } = useMutation14((apiKey) => {
2241
+ const deleteUrl = requiredLink(apiKey, "delete");
2242
+ return apiClient.delete(deleteUrl);
2243
+ }, {
2244
+ onSuccess: () => queryClient2.invalidateQueries(["user", user.name, "apiKeys"])
2245
+ });
2246
+ return {
2247
+ remove: (apiKey) => mutate(apiKey),
2248
+ isLoading,
2249
+ error,
2250
+ isDeleted: !!data
2251
+ };
2252
+ };
2253
+
2254
+ // src/publicKeys.ts
2255
+ import { useMutation as useMutation15, useQuery as useQuery20, useQueryClient as useQueryClient16 } from "react-query";
2256
+ var CONTENT_TYPE_PUBLIC_KEY = "application/vnd.scmm-publicKey+json;v=2";
2257
+ var usePublicKeys = (user) => useQuery20(["user", user.name, "publicKeys"], () => apiClient.get(requiredLink(user, "publicKeys")).then((r) => r.json()));
2258
+ var createPublicKey = (link) => async (key) => {
2259
+ const creationResponse = await apiClient.post(link, key, CONTENT_TYPE_PUBLIC_KEY);
2260
+ const location = creationResponse.headers.get("Location");
2261
+ if (!location) {
2262
+ throw new Error("Server does not return required Location header");
2263
+ }
2264
+ const apiKeyResponse = await apiClient.get(location);
2265
+ return apiKeyResponse.json();
2266
+ };
2267
+ var useCreatePublicKey = (user, publicKeys) => {
2268
+ const queryClient2 = useQueryClient16();
2269
+ const { mutate, data, isLoading, error, reset: reset2 } = useMutation15(createPublicKey(requiredLink(publicKeys, "create")), {
2270
+ onSuccess: () => queryClient2.invalidateQueries(["user", user.name, "publicKeys"])
2271
+ });
2272
+ return {
2273
+ create: (key) => mutate(key),
2274
+ isLoading,
2275
+ error,
2276
+ apiKey: data,
2277
+ reset: reset2
2278
+ };
2279
+ };
2280
+ var useDeletePublicKey = (user) => {
2281
+ const queryClient2 = useQueryClient16();
2282
+ const { mutate, isLoading, error, data } = useMutation15((publicKey) => {
2283
+ const deleteUrl = requiredLink(publicKey, "delete");
2284
+ return apiClient.delete(deleteUrl);
2285
+ }, {
2286
+ onSuccess: () => queryClient2.invalidateQueries(["user", user.name, "publicKeys"])
2287
+ });
2288
+ return {
2289
+ remove: (publicKey) => mutate(publicKey),
2290
+ isLoading,
2291
+ error,
2292
+ isDeleted: !!data
2293
+ };
2294
+ };
2295
+
2296
+ // src/fileContent.ts
2297
+ import { useQuery as useQuery21 } from "react-query";
2298
+ var useFileContent = (file) => {
2299
+ const selfLink = requiredLink(file, "self");
2300
+ return useQuery21(["fileContent", selfLink], () => apiClient.get(selfLink).then((response) => response.text()));
2301
+ };
2302
+
2303
+ // src/history.ts
2304
+ import { useQuery as useQuery22, useQueryClient as useQueryClient17 } from "react-query";
2305
+ var useHistory = (repository, revision, file, request) => {
2306
+ const queryClient2 = useQueryClient17();
2307
+ const link = file._links.history.href;
2308
+ const queryParams = {};
2309
+ if (request == null ? void 0 : request.page) {
2310
+ queryParams.page = request.page.toString();
2311
+ }
2312
+ return useQuery22(repoQueryKey(repository, "history", revision, file.path, (request == null ? void 0 : request.page) || 0), () => apiClient.get(`${link}?${createQueryString(queryParams)}`).then((response) => response.json()), {
2313
+ keepPreviousData: true,
2314
+ onSuccess: (changesets) => {
2315
+ var _a;
2316
+ (_a = changesets._embedded) == null ? void 0 : _a.changesets.forEach((changeset) => queryClient2.setQueryData(changesetQueryKey(repository, changeset.id), changeset));
2317
+ }
2318
+ });
2319
+ };
2320
+
2321
+ // src/contentType.ts
2322
+ import { useQuery as useQuery23 } from "react-query";
2323
+ function getContentType(url) {
2324
+ return apiClient.head(url).then((response) => {
2325
+ return {
2326
+ type: response.headers.get("Content-Type") || "application/octet-stream",
2327
+ language: response.headers.get("X-Programming-Language") || void 0,
2328
+ aceMode: response.headers.get("X-Syntax-Mode-Ace") || void 0,
2329
+ codemirrorMode: response.headers.get("X-Syntax-Mode-Codemirror") || void 0,
2330
+ prismMode: response.headers.get("X-Syntax-Mode-Prism") || void 0
2331
+ };
2332
+ });
2333
+ }
2334
+ var useContentType = (url) => {
2335
+ const { isLoading, isFetching, error, data } = useQuery23(["contentType", url], () => getContentType(url));
2336
+ return {
2337
+ isLoading,
2338
+ isFetching,
2339
+ error,
2340
+ data
2341
+ };
2342
+ };
2343
+
2344
+ // src/annotations.ts
2345
+ import { useQuery as useQuery24 } from "react-query";
2346
+ var useAnnotations = (repository, revision, file) => {
2347
+ const { isLoading, isFetching, error, data } = useQuery24(repoQueryKey(repository, "annotations", revision, file.path), () => apiClient.get(file._links.annotate.href).then((response) => response.json()));
2348
+ return {
2349
+ isLoading,
2350
+ isFetching,
2351
+ error,
2352
+ data
2353
+ };
2354
+ };
2355
+
2356
+ // src/search.ts
2357
+ import { useQueries, useQuery as useQuery25 } from "react-query";
2358
+ import { useEffect as useEffect5, useState as useState3 } from "react";
2359
+
2360
+ // src/help/search/syntax.en.ts
2361
+ var syntax_en_default = `### Modifiers
2362
+
2363
+ Note: You can not use wildcards as the first character of a search.
2364
+
2365
+ <table>
2366
+ <tr>
2367
+ <th>Definition</th>
2368
+ <th>Example</th>
2369
+ </tr>
2370
+ <tr>
2371
+ <td>? - single character Wildcard</td>
2372
+ <td>Ultimate?Repo \u2013 finds e.g. Ultimate-Repo, Ultimate Repo, Ultimate+Repo</td>
2373
+ </tr>
2374
+ <tr>
2375
+ <td>* - multiple character Wildcard</td>
2376
+ <td>Ultimat*y - finds e.g. Ultimate Repository, Ultimate-Special-Repository, Ultimately</td>
2377
+ </tr>
2378
+ </table>
2379
+
2380
+
2381
+ ### Ranges
2382
+
2383
+ Range Queries allow one to match documents whose field(s) values are between the lower and upper bound specified by the Range Query. Range Queries can be inclusive or exclusive of the upper and lower bounds. Sorting is done lexicographically.
2384
+
2385
+ Ranges are not reserved to numerical fields.
2386
+
2387
+ <table>
2388
+ <tr>
2389
+ <th>Definition</th>
2390
+ <th>Example</th>
2391
+ </tr>
2392
+ <tr>
2393
+ <td>[ \u2026 TO \u2026 ] - inclusive range</td>
2394
+ <td>creationDate:[1609459200000 TO 1612137600000] \u2013 finds e.G. repositories created between 2021-01-01 and 2021-02-01 </td>
2395
+ </tr>
2396
+ <tr>
2397
+ <td>{\u2026 TO \u2026} - exclusive range</td>
2398
+ <td>name:{Aida TO Carmen} \u2013 finds e.G. repositories with names between Aida and Carmen, excluding these to values.</td>
2399
+ </tr>
2400
+ </table>
2401
+
2402
+
2403
+ ### Boosting
2404
+
2405
+ Boosting allows you to control the relevance of a document by boosting its term.
2406
+
2407
+ <table>
2408
+ <tr>
2409
+ <th>Definition</th>
2410
+ <th>Example</th>
2411
+ </tr>
2412
+ <tr>
2413
+ <td>term^number</td>
2414
+ <td>ultimate^2 repository \u2013 makes the term "ultimate" more relevant. </td>
2415
+ </tr>
2416
+ </table>
2417
+
2418
+
2419
+ By default, the boost factor is 1. Although the boost factor must be positive, it can be less than 1 (e.g. 0.2)
2420
+
2421
+ By default Repository names are boosted by 1.5, namespace by 1.25.
2422
+
2423
+ ## Boolean Operators
2424
+
2425
+ Note: Logical Operators must be entered in upper case (e.g. "AND").
2426
+
2427
+ <table>
2428
+ <tr>
2429
+ <th>Definition</th>
2430
+ <th>Example</th>
2431
+ </tr>
2432
+ <tr>
2433
+ <td>AND \u2013 both terms must be included</td>
2434
+ <td>Ultimate AND Repository \u2013 finds e.g. Ultimate Repository, Ultimate Special Repository</td>
2435
+ </tr>
2436
+ <tr>
2437
+ <td>OR \u2013 at least one of the terms must be included</td>
2438
+ <td>Ultimate OR Repository \u2013 finds e.g. Ultimate Repository, Ultimate User, Special Repository</td>
2439
+ </tr>
2440
+ <tr>
2441
+ <td>NOT \u2013 following term may not be included, "!" may be used alternatively</td>
2442
+ <td>Ultimate NOT Repository \u2013 finds e.g. Ultimate user, excludes e.g. Ultimate Repository</td>
2443
+ </tr>
2444
+ <tr>
2445
+ <td>\u2013 excludes following term from search</td>
2446
+ <td>Ultimate Repository -Special \u2013 finds e.g. Ultimate Repository, excludes e.g. Ultimate Special Repository</td>
2447
+ </tr>
2448
+ <tr>
2449
+ <td>\u2013 following term must be included</td>
2450
+ <td>Ultimate +Repository \u2013 finds e.g. my Repository, Ultimate Repository</td>
2451
+ </tr>
2452
+ </table>
2453
+
2454
+
2455
+ ## Grouping
2456
+
2457
+ Search supports using parentheses to group clauses to form sub queries. This can be very useful if you want to control the boolean logic for a query.
2458
+
2459
+ <table>
2460
+ <tr>
2461
+ <th>Definition</th>
2462
+ <th>Example</th>
2463
+ </tr>
2464
+ <tr>
2465
+ <td>() \u2013 terms inside parentheses are grouped together</td>
2466
+ <td>(Ultimate OR my) AND Repository \u2013 finds e.g. Ultimate Repository, my Repository, excludes e.g. Super Repository. Either "Ultimate" or \u201CMy\u201D must exist, \u201CRepository\u201D must always exist.
2467
+ </td>
2468
+ </tr>
2469
+ </table>
2470
+
2471
+
2472
+ ## Escaping Special Characters
2473
+
2474
+ The search supports escaping special characters that are part of the query syntax. The current list special characters are
2475
+
2476
+ &plus; &minus; && || ! ( ) { } [ ] ^ " ~ * ? : &bsol; /
2477
+
2478
+ To escape these characters use the "&bsol;" before the character. For example to search for (1+1):2 use the query:
2479
+
2480
+ &bsol;(1&bsol;+1&bsol;)&bsol;:2
2481
+
2482
+ Source: [https://javadoc.io/static/org.apache.lucene/lucene-queryparser/8.9.0/org/apache/lucene/queryparser/classic/package-summary.html#package.description](https://javadoc.io/static/org.apache.lucene/lucene-queryparser/8.9.0/org/apache/lucene/queryparser/classic/package-summary.html#package.description)`;
2483
+
2484
+ // src/help/search/syntax.de.ts
2485
+ var syntax_de_default = `## Modifikatoren
2486
+
2487
+ Hinweis: Sie k\xF6nnen keine Wildcards als erstes Zeichen einer Suche verwenden.
2488
+
2489
+ <table>
2490
+ <tr>
2491
+ <th>Definition</th>
2492
+ <th>Beispiel</th>
2493
+ </tr>
2494
+ <tr>
2495
+ <td>? - Einzelzeichen-Wildcard</td>
2496
+ <td>Ultimate?Repo - findet z.B. Ultimate-Repo, Ultimate Repo, Ultimate+Repo</td>
2497
+ </tr>
2498
+ <tr>
2499
+ <td>* - mehrstelliger Platzhalter</td>
2500
+ <td>Ultimat*y - findet z.B. Ultimate Repository, Ultimates-Spezial-Repository, Ultimate</td>
2501
+ </tr>
2502
+ </table>
2503
+
2504
+
2505
+ ### Bereiche
2506
+
2507
+ Bereichsabfragen erm\xF6glichen den Abgleich von Dokumenten, deren Feldwerte zwischen der unteren und der oberen Grenze liegen, die in der Bereichsabfrage angegeben sind. Bereichsabfragen k\xF6nnen die obere und untere Grenze einschlie\xDFen oder ausschlie\xDFen. Die Sortierung erfolgt lexikografisch.
2508
+
2509
+ Bereiche sind nicht auf numerische Felder beschr\xE4nkt.
2510
+
2511
+ <table>
2512
+ <tr>
2513
+ <th>Definition</th>
2514
+ <th>Beispiel</th>
2515
+ </tr>
2516
+ <tr>
2517
+ <td>[ \u2026 TO \u2026 ] - inklusiver Bereich</td>
2518
+ <td>creationDate:[1609459200000 TO 1612137600000] \u2013 findet z.B. Repositories, die zwischen dem 01.01.2021 und dem 01.02.2021 angelegt wurden.</td>
2519
+ </tr>
2520
+ <tr>
2521
+ <td>{\u2026 TO \u2026} - ausschlie\xDFender Bereich</td>
2522
+ <td>name:{Aida TO Carmen} \u2013 findet Namen zwischen Aida und Carmen, jedoch ohne die beiden Namen einzuschlie\xDFen.</td>
2523
+ </tr>
2524
+ </table>
2525
+
2526
+
2527
+ ## Boosten
2528
+
2529
+ Mit dem Boosting k\xF6nnen Sie die Relevanz eines Dokuments steuern, indem Sie seinen Term verst\xE4rken.
2530
+
2531
+ <table>
2532
+ <tr>
2533
+ <th>Definition</th>
2534
+ <th>Beispiel</th>
2535
+ </tr>
2536
+ <tr>
2537
+ <td>term^Zahl</td>
2538
+ <td>ultimate^2 repository \u2013 erh\xF6ht die Relevanz von \u201Eultimate"</td>
2539
+ </tr>
2540
+ </table>
2541
+
2542
+
2543
+ Standardm\xE4\xDFig ist der Boost-Faktor 1. Obwohl der Boost-Faktor positiv sein muss, kann er kleiner als 1 sein (z. B. 0,2)
2544
+
2545
+ Standardm\xE4\xDFig werden Repository-Namen um 1,5 und Namespace-Namen um 1,25 geboostet.
2546
+
2547
+ ## Boolesche Operatoren
2548
+
2549
+ Hinweis: Logische Operatoren m\xFCssen in Gro\xDFbuchstaben eingegeben werden (z. B. \u201EAND").
2550
+
2551
+ <table>
2552
+ <tr>
2553
+ <th>Definition</th>
2554
+ <th>Beispiel</th>
2555
+ </tr>
2556
+ <tr>
2557
+ <td>AND \u2013 beide Terme m\xFCssen enthalten sein</td>
2558
+ <td>Ultimate AND Repository \u2013 findet z.B. Ultimate Repository, Ultimate Special Repository
2559
+ </td>
2560
+ </tr>
2561
+ <tr>
2562
+ <td>OR \u2013 mindestens einer der Terme muss enthalten sein</td>
2563
+ <td>Ultimate OR Repository \u2013 findet z.B.. Ultimate Repository, Ultimate User, Special Repository</td>
2564
+ </tr>
2565
+ <tr>
2566
+ <td>NOT \u2013 der nachfolgende Term darf nicht enthalten sein. \u201E!" kann alternativ verwendet werden.</td>
2567
+ <td>Ultimate NOT Repository \u2013 findet z.B.. Ultimate user, nicht jedoch z.B. Ultimate Repository</td>
2568
+ </tr>
2569
+ <tr>
2570
+ <td>\u2013 schlie\xDFt den folgenden Term von der Suche aus</td>
2571
+ <td>Ultimate Repository -Special \u2013 findet z.B. Ultimate Repository, schlie\xDFt z.B. Ultimate Special Repository aus</td>
2572
+ </tr>
2573
+ <tr>
2574
+ <td>\u2013 der folgende Term muss enthalten sein</td>
2575
+ <td>Ultimate +Repository \u2013 findet z.B. my Repository, Ultimate Repository</td>
2576
+ </tr>
2577
+ </table>
2578
+
2579
+
2580
+ ## Gruppieren
2581
+
2582
+ Die Suche unterst\xFCtzt die Verwendung von Klammern zur Gruppierung von Begriffen, um Teilabfragen zu bilden. Dies kann sehr n\xFCtzlich sein, wenn Sie die boolesche Logik f\xFCr eine Abfrage steuern m\xF6chten.
2583
+
2584
+ <table>
2585
+ <tr>
2586
+ <th>Definition</th>
2587
+ <th>Beispiel</th>
2588
+ </tr>
2589
+ <tr>
2590
+ <td>() \u2013 Terme zwischen den Klammern werden gruppiert</td>
2591
+ <td>(Ultimate OR my) AND Repository \u2013 findet z.B.. Ultimate Repository, my Repository, schlie\xDFt z.B. Super Repository. Entweder "Ultimate" oder \u201CMy\u201D m\xFCssen im Ergebnis existieren, \u201CRepository\u201D muss immer enthalten sein.
2592
+ </td>
2593
+ </tr>
2594
+ </table>
2595
+
2596
+
2597
+ ## Umgang mit Sonderzeichen
2598
+
2599
+ Die Suche unterst\xFCtzt Sonderzeichen, die Teil der Abfragesyntax sind. Die aktuellen Sonderzeichen der Liste sind
2600
+
2601
+ &plus; &minus; && || ! ( ) { } [ ] ^ " ~ * ? : &bsol; /
2602
+
2603
+ Um diese Zeichen zu nutzen, verwenden Sie \u201E&bsol;" vor dem jeweiligen Zeichen. Um zum Beispiel nach (1+1):2 zu suchen, verwenden Sie diese Abfrage:
2604
+
2605
+ &bsol;(1&bsol;+1&bsol;)&bsol;:2
2606
+
2607
+ Partiell \xFCbersetzt mit www.DeepL.com/Translator (kostenlose Version)
2608
+
2609
+ Quelle [https://javadoc.io/static/org.apache.lucene/lucene-queryparser/8.9.0/org/apache/lucene/queryparser/classic/package-summary.html#package.description](https://javadoc.io/static/org.apache.lucene/lucene-queryparser/8.9.0/org/apache/lucene/queryparser/classic/package-summary.html#package.description)`;
2610
+
2611
+ // src/help/search/syntax.ts
2612
+ var syntax_default = {
2613
+ de: syntax_de_default,
2614
+ en: syntax_en_default
2615
+ };
2616
+
2617
+ // src/help/search/modal.en.ts
2618
+ var modal_en_default = `Our search uses Lucene and you may use the [full syntax](http://lucene.apache.org/core/8_9_0/index.html).
2619
+
2620
+ To learn about advanced search read our [Expert Search Site](/help/search-syntax).
2621
+
2622
+ ### Basic Search
2623
+
2624
+ - The most relevant repositories are shown in the quick results.
2625
+ - Press "enter" or click the "Show all results" button to find more results for all entities like users or groups.
2626
+ - A multi-character wildcard (*) is added to your search by default.
2627
+ - Do not enter Wildcards in front of the search!`;
2628
+
2629
+ // src/help/search/modal.de.ts
2630
+ var modal_de_default = `Unsere Suche basiert auf Lucene. Sie k\xF6nnen die [vollst\xE4ndige Syntax](http://lucene.apache.org/core/8_9_0/index.html) nutzen.
2631
+
2632
+ Um mehr \xFCber die fortgeschrittene Suche zu erfahren, lesen sie unsere [Expertenseite](/help/search-syntax).
2633
+
2634
+ ### Einfache Suche
2635
+
2636
+ - Die relevantesten Repositories werden in den Quick Results angezeigt.
2637
+ - \xDCber die Eingabe-Taste oder den Button "Alle Ergebnisse anzeigen" bekommen Sie Ergebnisse aller durchsuchten Entit\xE4ten wie Nutzern oder Gruppen.
2638
+ - Eine Wildcard f\xFCr eine beliebige Anzahl an beliebigen Zeichen wird Ihrer Suche standardm\xE4\xDFig angeh\xE4ngt.
2639
+ - Geben Sie keine Wildcards vor dem Suchbegriff ein!`;
2640
+
2641
+ // src/help/search/modal.ts
2642
+ var modal_default = {
2643
+ de: modal_de_default,
2644
+ en: modal_en_default
2645
+ };
2646
+
2647
+ // src/search.ts
2648
+ var defaultSearchOptions = {
2649
+ type: "repository"
2650
+ };
2651
+ var isString = (str) => !!str;
2652
+ var useSearchTypes = () => {
2653
+ return useSearchLinks().map((link) => link.name).filter(isString);
2654
+ };
2655
+ var useSearchableTypes = () => useIndexJsonResource("searchableTypes");
2656
+ var useSearchCounts = (types, query) => {
2657
+ const searchLinks = useSearchLinks();
2658
+ const queries = useQueries(types.map((type) => ({
2659
+ queryKey: ["search", type, query, "count"],
2660
+ queryFn: () => apiClient.get(`${findLink(searchLinks, type)}?q=${query}&countOnly=true`).then((response) => response.json())
2661
+ })));
2662
+ const result = {};
2663
+ queries.forEach((q, i) => {
2664
+ var _a;
2665
+ result[types[i]] = {
2666
+ isLoading: q.isLoading,
2667
+ isFetching: q.isFetching,
2668
+ error: q.error,
2669
+ data: (_a = q.data) == null ? void 0 : _a.totalHits
2670
+ };
2671
+ });
2672
+ return result;
2673
+ };
2674
+ var findLink = (links, name) => {
2675
+ for (const l of links) {
2676
+ if (l.name === name) {
2677
+ return l.href;
2678
+ }
2679
+ }
2680
+ throw new Error(`could not find search link for ${name}`);
2681
+ };
2682
+ var useSearchLinks = () => {
2683
+ const links = useIndexLinks();
2684
+ const searchLinks = links["search"];
2685
+ if (!searchLinks) {
2686
+ throw new Error("could not find search links in index");
2687
+ }
2688
+ if (!Array.isArray(searchLinks)) {
2689
+ throw new Error("search links returned in wrong format, array is expected");
2690
+ }
2691
+ return searchLinks;
2692
+ };
2693
+ var useSearchLink = (name) => {
2694
+ const searchLinks = useSearchLinks();
2695
+ return findLink(searchLinks, name);
2696
+ };
2697
+ var useSearch = (query, optionParam = defaultSearchOptions) => {
2698
+ const options = __spreadValues(__spreadValues({}, defaultSearchOptions), optionParam);
2699
+ const link = useSearchLink(options.type);
2700
+ const queryParams = {};
2701
+ queryParams.q = query;
2702
+ if (options.page) {
2703
+ queryParams.page = options.page.toString();
2704
+ }
2705
+ if (options.pageSize) {
2706
+ queryParams.pageSize = options.pageSize.toString();
2707
+ }
2708
+ return useQuery25(["search", options.type, queryParams], () => apiClient.get(`${link}?${createQueryString(queryParams)}`).then((response) => response.json()), {
2709
+ enabled: (query == null ? void 0 : query.length) > 1
2710
+ });
2711
+ };
2712
+ var useObserveAsync = (fn, deps) => {
2713
+ const [data, setData] = useState3();
2714
+ const [isLoading, setLoading] = useState3(false);
2715
+ const [error, setError] = useState3();
2716
+ useEffect5(() => {
2717
+ setLoading(true);
2718
+ fn(...deps).then(setData).catch(setError).finally(() => setLoading(false));
2719
+ }, deps);
2720
+ return { data, isLoading, error };
2721
+ };
2722
+ var getTypedKeys = (input) => Object.keys(input);
2723
+ var isSupportedLanguage = (input, supportedLanguages) => supportedLanguages.includes(input);
2724
+ var pickLang = (language, supportedLanguages, fallback) => isSupportedLanguage(language, supportedLanguages) ? language : fallback;
2725
+ var SUPPORTED_MODAL_LANGUAGES = getTypedKeys(modal_default);
2726
+ var SUPPORTED_SYNTAX_LANGUAGES = getTypedKeys(syntax_default);
2727
+ var FALLBACK_LANGUAGE = "en";
2728
+ var useSearchHelpContent = (language) => useObserveAsync((lang) => Promise.resolve(modal_default[pickLang(lang, SUPPORTED_MODAL_LANGUAGES, FALLBACK_LANGUAGE)]), [language]);
2729
+ var useSearchSyntaxContent = (language) => useObserveAsync((lang) => Promise.resolve(syntax_default[pickLang(lang, SUPPORTED_SYNTAX_LANGUAGES, FALLBACK_LANGUAGE)]), [language]);
2730
+
2731
+ // src/loginInfo.ts
2732
+ import { useQuery as useQuery26 } from "react-query";
2733
+ var useLoginInfo = (disabled = false) => {
2734
+ const loginInfoLink = useIndexLink("loginInfo");
2735
+ const { error, isLoading, data } = useQuery26(["loginInfo"], () => fetch(loginInfoLink).then((response) => response.json()), {
2736
+ enabled: !disabled && !!loginInfoLink,
2737
+ refetchOnWindowFocus: false
2738
+ });
2739
+ return {
2740
+ data,
2741
+ error,
2742
+ isLoading
2743
+ };
2744
+ };
2745
+
2746
+ // src/usePluginCenterAuthInfo.ts
2747
+ import { useMutation as useMutation16, useQuery as useQuery27, useQueryClient as useQueryClient18 } from "react-query";
2748
+ import { useLocation } from "react-router-dom";
2749
+ var appendQueryParam = (link, name, value) => {
2750
+ let href = link.href;
2751
+ if (href.includes("?")) {
2752
+ href += "&";
2753
+ } else {
2754
+ href += "?";
2755
+ }
2756
+ link.href = href + name + "=" + value;
2757
+ };
2758
+ var usePluginCenterAuthInfo = () => {
2759
+ const link = useIndexLink("pluginCenterAuth");
2760
+ const location = useLocation();
2761
+ return useQuery27(["pluginCenterAuth"], () => {
2762
+ if (!link) {
2763
+ throw new Error("no such plugin center auth link");
2764
+ }
2765
+ return apiClient.get(link).then((response) => response.json()).then((result) => {
2766
+ var _a, _b;
2767
+ if ((_a = result._links) == null ? void 0 : _a.login) {
2768
+ appendQueryParam(result._links.login, "source", location.pathname);
2769
+ }
2770
+ if ((_b = result._links) == null ? void 0 : _b.reconnect) {
2771
+ appendQueryParam(result._links.reconnect, "source", location.pathname);
2772
+ }
2773
+ return result;
2774
+ });
2775
+ }, {
2776
+ enabled: !!link
2777
+ });
2778
+ };
2779
+ var usePluginCenterLogout = (authenticationInfo) => {
2780
+ const queryClient2 = useQueryClient18();
2781
+ const { mutate, isLoading, error } = useMutation16(() => {
2782
+ if (!authenticationInfo._links.logout) {
2783
+ throw new Error("authenticationInfo has no logout link");
2784
+ }
2785
+ const logout = authenticationInfo._links.logout;
2786
+ return apiClient.delete(logout.href);
2787
+ }, {
2788
+ onSuccess: () => queryClient2.invalidateQueries("pluginCenterAuth")
2789
+ });
2790
+ return {
2791
+ logout: () => {
2792
+ mutate();
2793
+ },
2794
+ isLoading,
2795
+ error
2796
+ };
2797
+ };
2798
+
2799
+ // src/compare.ts
2800
+ import { useQuery as useQuery28, useQueryClient as useQueryClient19 } from "react-query";
2801
+ function createIncomingUrl(repository, linkName, source, target) {
2802
+ const link = repository._links[linkName];
2803
+ if (link == null ? void 0 : link.templated) {
2804
+ return link.href.replace("{source}", encodeURIComponent(source)).replace("{target}", encodeURIComponent(target));
2805
+ } else {
2806
+ return link.href;
2807
+ }
2808
+ }
2809
+ function createChangesetUrl(repository, source, target) {
2810
+ return createIncomingUrl(repository, "incomingChangesets", source, target);
2811
+ }
2812
+ function createDiffUrl(repository, source, target) {
2813
+ if (repository._links.incomingDiffParsed) {
2814
+ return createIncomingUrl(repository, "incomingDiffParsed", source, target);
2815
+ } else {
2816
+ return createIncomingUrl(repository, "incomingDiff", source, target);
2817
+ }
2818
+ }
2819
+ var useIncomingChangesets = (repository, source, target, request) => {
2820
+ const queryClient2 = useQueryClient19();
2821
+ let link = createChangesetUrl(repository, source, target);
2822
+ if ((request == null ? void 0 : request.page) || (request == null ? void 0 : request.limit)) {
2823
+ if ((request == null ? void 0 : request.page) && (request == null ? void 0 : request.limit)) {
2824
+ link = `${link}?page=${request.page}&pageSize=${request.limit}`;
2825
+ } else if (request.page) {
2826
+ link = `${link}?page=${request.page}`;
2827
+ } else if (request.limit) {
2828
+ link = `${link}?pageSize=${request.limit}`;
2829
+ }
2830
+ }
2831
+ return useQuery28(["repository", repository.namespace, repository.name, "compare", source, target, "changesets", (request == null ? void 0 : request.page) || 0], () => apiClient.get(link).then((response) => response.json()), {
2832
+ onSuccess: (changesetCollection) => {
2833
+ var _a;
2834
+ (_a = changesetCollection._embedded) == null ? void 0 : _a.changesets.forEach((changeset) => {
2835
+ queryClient2.setQueryData(changesetQueryKey(repository, changeset.id), changeset);
2836
+ });
2837
+ }
2838
+ });
2839
+ };
2840
+
2841
+ // src/ApiProvider.tsx
2842
+ import React2, { useEffect as useEffect6 } from "react";
2843
+ import { QueryClient as QueryClient4, QueryClientProvider } from "react-query";
2844
+ import { ReactQueryDevtools } from "react-query/devtools";
2845
+ var queryClient = new QueryClient4({
2846
+ defaultOptions: {
2847
+ queries: {
2848
+ retry: false
2849
+ }
2850
+ }
2851
+ });
2852
+ var ApiProvider = ({ children, index, me, onMeFetched, onIndexFetched, devtools = true }) => {
2853
+ useEffect6(() => {
2854
+ if (index) {
2855
+ queryClient.setQueryData("index", index);
2856
+ if (onIndexFetched) {
2857
+ onIndexFetched(index);
2858
+ }
2859
+ }
2860
+ }, [index, onIndexFetched]);
2861
+ useEffect6(() => {
2862
+ if (me) {
2863
+ queryClient.setQueryData("me", me);
2864
+ if (onMeFetched) {
2865
+ onMeFetched(me);
2866
+ }
2867
+ }
2868
+ }, [me, onMeFetched]);
2869
+ return /* @__PURE__ */ React2.createElement(QueryClientProvider, {
2870
+ client: queryClient
2871
+ }, /* @__PURE__ */ React2.createElement(LegacyContextProvider, {
2872
+ onIndexFetched,
2873
+ onMeFetched
2874
+ }, children), devtools ? /* @__PURE__ */ React2.createElement(ReactQueryDevtools, {
2875
+ initialIsOpen: false
2876
+ }) : null);
2877
+ };
2878
+ var clearCache = () => {
2879
+ return reset(queryClient);
2880
+ };
2881
+ var ApiProvider_default = ApiProvider;
2882
+ export {
2883
+ ApiProvider_default as ApiProvider,
2884
+ BackendError,
2885
+ BadGatewayError,
2886
+ CONTENT_TYPE_PUBLIC_KEY,
2887
+ ConflictError,
2888
+ ForbiddenError,
2889
+ LegacyContextProvider,
2890
+ MissingLinkError,
2891
+ NotFoundError,
2892
+ TOKEN_EXPIRED_ERROR_CODE,
2893
+ TokenExpiredError,
2894
+ UnauthorizedError,
2895
+ apiClient,
2896
+ changesetQueryKey,
2897
+ clearCache,
2898
+ createBackendError,
2899
+ createChangesetUrl,
2900
+ createDiffUrl,
2901
+ createQueryString,
2902
+ createUrl,
2903
+ createUrlWithIdentifiers,
2904
+ extractXsrfTokenFromCookie,
2905
+ fetchResourceFromLocationHeader,
2906
+ getResponseJson,
2907
+ isBackendError,
2908
+ objectLink,
2909
+ requiredLink,
2910
+ urls_exports as urls,
2911
+ useAlerts,
2912
+ useAnnotations,
2913
+ useApiKeys,
2914
+ useArchiveRepository,
2915
+ useAvailableGlobalPermissions,
2916
+ useAvailablePermissions,
2917
+ useAvailablePlugins,
2918
+ useBranch,
2919
+ useBranchDetails,
2920
+ useBranchDetailsCollection,
2921
+ useBranches,
2922
+ useCancelPendingPlugins,
2923
+ useChangeUserPassword,
2924
+ useChangeset,
2925
+ useChangesets,
2926
+ useClearNotifications,
2927
+ useConfig,
2928
+ useConfigLink,
2929
+ useContentType,
2930
+ useConvertToExternal,
2931
+ useConvertToInternal,
2932
+ useCreateApiKey,
2933
+ useCreateBranch,
2934
+ useCreateGroup,
2935
+ useCreatePermission,
2936
+ useCreatePublicKey,
2937
+ useCreateRepository,
2938
+ useCreateRepositoryRole,
2939
+ useCreateTag,
2940
+ useCreateUser,
2941
+ useDefaultBranch,
2942
+ useDeleteApiKey,
2943
+ useDeleteBranch,
2944
+ useDeleteGroup,
2945
+ useDeletePermission,
2946
+ useDeletePublicKey,
2947
+ useDeleteRepository,
2948
+ useDeleteRepositoryRole,
2949
+ useDeleteTag,
2950
+ useDeleteUser,
2951
+ useDiff,
2952
+ useDismissNotification,
2953
+ useExecutePendingPlugins,
2954
+ useExportInfo,
2955
+ useExportRepository,
2956
+ useFileContent,
2957
+ useGroup,
2958
+ useGroupPermissions,
2959
+ useGroupSuggestions,
2960
+ useGroups,
2961
+ useHistory,
2962
+ useImportFullRepository,
2963
+ useImportLog,
2964
+ useImportRepositoryFromBundle,
2965
+ useImportRepositoryFromUrl,
2966
+ useIncomingChangesets,
2967
+ useIndex,
2968
+ useIndexJsonResource,
2969
+ useIndexLink,
2970
+ useIndexLinks,
2971
+ useInstallPlugin,
2972
+ useInstalledPlugins,
2973
+ useJsonResource,
2974
+ useLegacyContext,
2975
+ useLogin,
2976
+ useLoginInfo,
2977
+ useLogout,
2978
+ useMe,
2979
+ useNamespace,
2980
+ useNamespaceStrategies,
2981
+ useNamespaceSuggestions,
2982
+ useNamespaces,
2983
+ useNotificationSubscription,
2984
+ useNotifications,
2985
+ usePaths,
2986
+ usePendingPlugins,
2987
+ usePermissions,
2988
+ usePluginCenterAuthInfo,
2989
+ usePluginCenterLogout,
2990
+ usePublicKeys,
2991
+ useRenameRepository,
2992
+ useRepositories,
2993
+ useRepository,
2994
+ useRepositoryRole,
2995
+ useRepositoryRoles,
2996
+ useRepositoryTypes,
2997
+ useRepositoryVerbs,
2998
+ useRequiredIndexLink,
2999
+ useRequiredMe,
3000
+ useRunHealthCheck,
3001
+ useSearch,
3002
+ useSearchCounts,
3003
+ useSearchHelpContent,
3004
+ useSearchSyntaxContent,
3005
+ useSearchTypes,
3006
+ useSearchableTypes,
3007
+ useSetGroupPermissions,
3008
+ useSetUserPassword,
3009
+ useSetUserPermissions,
3010
+ useSources,
3011
+ useSubject,
3012
+ useSuggestions,
3013
+ useTag,
3014
+ useTags,
3015
+ useUnarchiveRepository,
3016
+ useUninstallPlugin,
3017
+ useUpdateConfig,
3018
+ useUpdateGroup,
3019
+ useUpdateInfo,
3020
+ useUpdatePermission,
3021
+ useUpdatePlugins,
3022
+ useUpdateRepository,
3023
+ useUpdateRepositoryRole,
3024
+ useUpdateUser,
3025
+ useUser,
3026
+ useUserPermissions,
3027
+ useUserSuggestions,
3028
+ useUsers,
3029
+ useVersion,
3030
+ waitForRestartAfter
3031
+ };