@scm-manager/ui-api 2.33.1-20220411-113741 → 2.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scm-manager/ui-api",
3
- "version": "2.33.1-20220411-113741",
3
+ "version": "2.34.0",
4
4
  "description": "React hook api for the SCM-Manager backend",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -25,7 +25,7 @@
25
25
  "react-test-renderer": "^17.0.1"
26
26
  },
27
27
  "dependencies": {
28
- "@scm-manager/ui-types": "^2.33.1-20220411-113741",
28
+ "@scm-manager/ui-types": "^2.34.0",
29
29
  "fetch-mock-jest": "^1.5.1",
30
30
  "gitdiff-parser": "^0.2.2",
31
31
  "query-string": "6.14.1",
@@ -36,7 +36,7 @@ describe("ApiProvider tests", () => {
36
36
 
37
37
  it("should register QueryClient", () => {
38
38
  const { result } = renderHook(() => useQueryClient(), {
39
- wrapper: createWrapper({ initialize: () => null }),
39
+ wrapper: createWrapper({ initialize: () => null })
40
40
  });
41
41
  expect(result.current).toBeDefined();
42
42
  });
@@ -48,7 +48,7 @@ describe("ApiProvider tests", () => {
48
48
  };
49
49
 
50
50
  const { result } = renderHook(() => useLegacyContext(), {
51
- wrapper: createWrapper({ onIndexFetched, initialize: () => null }),
51
+ wrapper: createWrapper({ onIndexFetched, initialize: () => null })
52
52
  });
53
53
 
54
54
  if (result.current?.onIndexFetched) {
@@ -31,9 +31,9 @@ import { reset } from "./reset";
31
31
  const queryClient = new QueryClient({
32
32
  defaultOptions: {
33
33
  queries: {
34
- retry: false,
35
- },
36
- },
34
+ retry: false
35
+ }
36
+ }
37
37
  });
38
38
 
39
39
  type Props = LegacyContext & {
@@ -40,7 +40,7 @@ describe("LegacyContext tests", () => {
40
40
 
41
41
  it("should return provided context", () => {
42
42
  const { result } = renderHook(() => useLegacyContext(), {
43
- wrapper: createWrapper(),
43
+ wrapper: createWrapper()
44
44
  });
45
45
  expect(result.current).toBeDefined();
46
46
  });
@@ -32,7 +32,7 @@ export type BaseContext = {
32
32
  };
33
33
 
34
34
  export type LegacyContext = BaseContext & {
35
- initialize?: () => void;
35
+ initialize: () => void;
36
36
  };
37
37
 
38
38
  const Context = createContext<LegacyContext | undefined>(undefined);
@@ -61,7 +61,7 @@ const createInitialContext = (queryClient: QueryClient, base: BaseContext): Lega
61
61
  ctx.onMeFetched(me);
62
62
  }
63
63
  }
64
- },
64
+ }
65
65
  };
66
66
 
67
67
  return ctx;
package/src/alerts.ts CHANGED
@@ -51,21 +51,21 @@ const fetchAlerts = (request: AlertRequest) => {
51
51
  return fetch(url, {
52
52
  method: "POST",
53
53
  headers: {
54
- "Content-Type": "application/json",
54
+ "Content-Type": "application/json"
55
55
  },
56
- body: JSON.stringify(request.body),
56
+ body: JSON.stringify(request.body)
57
57
  })
58
- .then((response) => {
58
+ .then(response => {
59
59
  if (!response.ok) {
60
60
  throw new Error("Failed to fetch alerts");
61
61
  }
62
62
  return response;
63
63
  })
64
- .then((response) => response.json())
64
+ .then(response => response.json())
65
65
  .then((data: AlertsResponse) => {
66
66
  const storageItem: LocalStorageAlerts = {
67
67
  ...data,
68
- checksum: request.checksum,
68
+ checksum: request.checksum
69
69
  };
70
70
  localStorage.setItem("alerts", JSON.stringify(storageItem));
71
71
  return data;
@@ -90,18 +90,18 @@ export const useAlerts = (): ApiResult<AlertsResponse> => {
90
90
  }
91
91
  return apiClient
92
92
  .get(link)
93
- .then((response) => response.json())
93
+ .then(response => response.json())
94
94
  .then(restoreOrFetch);
95
95
  },
96
96
  {
97
97
  enabled: !!link,
98
- staleTime: Infinity,
98
+ staleTime: Infinity
99
99
  }
100
100
  );
101
101
 
102
102
  return {
103
103
  data,
104
104
  error,
105
- isLoading,
105
+ isLoading
106
106
  };
107
107
  };
@@ -45,9 +45,9 @@ describe("error handling tests", () => {
45
45
  context: [
46
46
  {
47
47
  type: "planet",
48
- id: "earth",
49
- },
50
- ],
48
+ id: "earth"
49
+ }
50
+ ]
51
51
  };
52
52
 
53
53
  afterEach(() => {
@@ -55,9 +55,9 @@ describe("error handling tests", () => {
55
55
  fetchMock.restore();
56
56
  });
57
57
 
58
- it("should create a normal error, if the content type is not scmm-error", (done) => {
58
+ it("should create a normal error, if the content type is not scmm-error", done => {
59
59
  fetchMock.getOnce("/api/v2/error", {
60
- status: 404,
60
+ status: 404
61
61
  });
62
62
 
63
63
  apiClient.get("/error").catch((err: Error) => {
@@ -67,9 +67,9 @@ describe("error handling tests", () => {
67
67
  });
68
68
  });
69
69
 
70
- it("should create a bad gateway error", (done) => {
70
+ it("should create a bad gateway error", done => {
71
71
  fetchMock.getOnce("/api/v2/error", {
72
- status: 502,
72
+ status: 502
73
73
  });
74
74
 
75
75
  apiClient.get("/error").catch((err: Error) => {
@@ -78,13 +78,13 @@ describe("error handling tests", () => {
78
78
  });
79
79
  });
80
80
 
81
- it("should create an backend error, if the content type is scmm-error", (done) => {
81
+ it("should create an backend error, if the content type is scmm-error", done => {
82
82
  fetchMock.getOnce("/api/v2/error", {
83
83
  status: 404,
84
84
  headers: {
85
- "Content-Type": "application/vnd.scmm-error+json;v=2",
85
+ "Content-Type": "application/vnd.scmm-error+json;v=2"
86
86
  },
87
- body: earthNotFoundError,
87
+ body: earthNotFoundError
88
88
  });
89
89
 
90
90
  apiClient.get("/error").catch((err: BackendError) => {
@@ -98,8 +98,8 @@ describe("error handling tests", () => {
98
98
  expect(err.context).toEqual([
99
99
  {
100
100
  type: "planet",
101
- id: "earth",
102
- },
101
+ id: "earth"
102
+ }
103
103
  ]);
104
104
  done();
105
105
  });
package/src/apiclient.ts CHANGED
@@ -31,7 +31,7 @@ import {
31
31
  isBackendError,
32
32
  TOKEN_EXPIRED_ERROR_CODE,
33
33
  TokenExpiredError,
34
- UnauthorizedError,
34
+ UnauthorizedError
35
35
  } from "./errors";
36
36
 
37
37
  type SubscriptionEvent = {
@@ -63,7 +63,12 @@ type SubscriptionArgument = MessageListeners | SubscriptionContext;
63
63
 
64
64
  type Cancel = () => void;
65
65
 
66
- const sessionId = (Date.now().toString(36) + Math.random().toString(36).substr(2, 5)).toUpperCase();
66
+ const sessionId = (
67
+ Date.now().toString(36) +
68
+ Math.random()
69
+ .toString(36)
70
+ .substr(2, 5)
71
+ ).toUpperCase();
67
72
 
68
73
  const extractXsrfTokenFromJwt = (jwt: string) => {
69
74
  const parts = jwt.split(".");
@@ -98,7 +103,7 @@ const createRequestHeaders = () => {
98
103
  // identify the web interface
99
104
  "X-SCM-Client": "WUI",
100
105
  // identify the window session
101
- "X-SCM-Session-ID": sessionId,
106
+ "X-SCM-Session-ID": sessionId
102
107
  };
103
108
 
104
109
  const xsrf = extractXsrfToken();
@@ -108,10 +113,10 @@ const createRequestHeaders = () => {
108
113
  return headers;
109
114
  };
110
115
 
111
- const applyFetchOptions: (p: RequestInit) => RequestInit = (o) => {
116
+ const applyFetchOptions: (p: RequestInit) => RequestInit = o => {
112
117
  if (o.headers) {
113
118
  o.headers = {
114
- ...createRequestHeaders(),
119
+ ...createRequestHeaders()
115
120
  };
116
121
  } else {
117
122
  o.headers = createRequestHeaders();
@@ -172,7 +177,9 @@ class ApiClient {
172
177
  requestListeners: RequestListener[] = [];
173
178
 
174
179
  get = (url: string): Promise<Response> => {
175
- return this.request(url, applyFetchOptions({})).then(handleFailure).catch(this.notifyAndRethrow);
180
+ return this.request(url, applyFetchOptions({}))
181
+ .then(handleFailure)
182
+ .catch(this.notifyAndRethrow);
176
183
  };
177
184
 
178
185
  post = (
@@ -199,7 +206,7 @@ class ApiClient {
199
206
  const options: RequestInit = {
200
207
  method: "POST",
201
208
  body: formData,
202
- headers: additionalHeaders,
209
+ headers: additionalHeaders
203
210
  };
204
211
  return this.httpRequestWithBinaryBody(options, url);
205
212
  };
@@ -210,18 +217,22 @@ class ApiClient {
210
217
 
211
218
  head = (url: string) => {
212
219
  let options: RequestInit = {
213
- method: "HEAD",
220
+ method: "HEAD"
214
221
  };
215
222
  options = applyFetchOptions(options);
216
- return this.request(url, options).then(handleFailure).catch(this.notifyAndRethrow);
223
+ return this.request(url, options)
224
+ .then(handleFailure)
225
+ .catch(this.notifyAndRethrow);
217
226
  };
218
227
 
219
228
  delete = (url: string): Promise<Response> => {
220
229
  let options: RequestInit = {
221
- method: "DELETE",
230
+ method: "DELETE"
222
231
  };
223
232
  options = applyFetchOptions(options);
224
- return this.request(url, options).then(handleFailure).catch(this.notifyAndRethrow);
233
+ return this.request(url, options)
234
+ .then(handleFailure)
235
+ .catch(this.notifyAndRethrow);
225
236
  };
226
237
 
227
238
  httpRequestWithJSONBody = (
@@ -233,7 +244,7 @@ class ApiClient {
233
244
  ): Promise<Response> => {
234
245
  const options: RequestInit = {
235
246
  method: method,
236
- headers: additionalHeaders,
247
+ headers: additionalHeaders
237
248
  };
238
249
  if (payload) {
239
250
  options.body = JSON.stringify(payload);
@@ -249,7 +260,7 @@ class ApiClient {
249
260
  ) => {
250
261
  const options: RequestInit = {
251
262
  method: method,
252
- headers: additionalHeaders,
263
+ headers: additionalHeaders
253
264
  };
254
265
  options.body = payload;
255
266
  return this.httpRequestWithBinaryBody(options, url, "text/plain");
@@ -265,12 +276,14 @@ class ApiClient {
265
276
  options.headers["Content-Type"] = contentType;
266
277
  }
267
278
 
268
- return this.request(url, options).then(handleFailure).catch(this.notifyAndRethrow);
279
+ return this.request(url, options)
280
+ .then(handleFailure)
281
+ .catch(this.notifyAndRethrow);
269
282
  };
270
283
 
271
284
  subscribe(url: string, argument: SubscriptionArgument): Cancel {
272
285
  const es = new EventSource(createUrlWithIdentifiers(url), {
273
- withCredentials: true,
286
+ withCredentials: true
274
287
  });
275
288
 
276
289
  let listeners: MessageListeners;
@@ -311,11 +324,11 @@ class ApiClient {
311
324
  };
312
325
 
313
326
  private notifyRequestListeners = (url: string, options: RequestInit) => {
314
- this.requestListeners.forEach((requestListener) => requestListener(url, options));
327
+ this.requestListeners.forEach(requestListener => requestListener(url, options));
315
328
  };
316
329
 
317
330
  private notifyAndRethrow = (error: Error): never => {
318
- this.errorListeners.forEach((errorListener) => errorListener(error));
331
+ this.errorListeners.forEach(errorListener => errorListener(error));
319
332
  throw error;
320
333
  };
321
334
  }
package/src/base.test.ts CHANGED
@@ -34,7 +34,7 @@ describe("Test base api hooks", () => {
34
34
  describe("useIndex tests", () => {
35
35
  fetchMock.get("/api/v2/", {
36
36
  version: "x.y.z",
37
- _links: {},
37
+ _links: {}
38
38
  });
39
39
 
40
40
  it("should return index", async () => {
@@ -48,10 +48,10 @@ describe("Test base api hooks", () => {
48
48
  it("should call onIndexFetched of LegacyContext", async () => {
49
49
  let index: IndexResources;
50
50
  const context: LegacyContext = {
51
- onIndexFetched: (fetchedIndex) => {
51
+ onIndexFetched: fetchedIndex => {
52
52
  index = fetchedIndex;
53
53
  },
54
- initialize: () => null,
54
+ initialize: () => null
55
55
  };
56
56
  const { result, waitFor } = renderHook(() => useIndex(), { wrapper: createWrapper(context) });
57
57
  await waitFor(() => {
@@ -71,10 +71,10 @@ describe("Test base api hooks", () => {
71
71
  const queryClient = new QueryClient();
72
72
  queryClient.setQueryData("index", {
73
73
  version: "x.y.z",
74
- _links: {},
74
+ _links: {}
75
75
  });
76
76
  const { result } = renderHook(() => useIndexLink("spaceships"), {
77
- wrapper: createWrapper(undefined, queryClient),
77
+ wrapper: createWrapper(undefined, queryClient)
78
78
  });
79
79
  expect(result.current).toBeUndefined();
80
80
  });
@@ -87,17 +87,17 @@ describe("Test base api hooks", () => {
87
87
  spaceships: [
88
88
  {
89
89
  name: "heartOfGold",
90
- href: "/spaceships/heartOfGold",
90
+ href: "/spaceships/heartOfGold"
91
91
  },
92
92
  {
93
93
  name: "razorCrest",
94
- href: "/spaceships/razorCrest",
95
- },
96
- ],
97
- },
94
+ href: "/spaceships/razorCrest"
95
+ }
96
+ ]
97
+ }
98
98
  });
99
99
  const { result } = renderHook(() => useIndexLink("spaceships"), {
100
- wrapper: createWrapper(undefined, queryClient),
100
+ wrapper: createWrapper(undefined, queryClient)
101
101
  });
102
102
  expect(result.current).toBeUndefined();
103
103
  });
@@ -108,12 +108,12 @@ describe("Test base api hooks", () => {
108
108
  version: "x.y.z",
109
109
  _links: {
110
110
  spaceships: {
111
- href: "/api/spaceships",
112
- },
113
- },
111
+ href: "/api/spaceships"
112
+ }
113
+ }
114
114
  });
115
115
  const { result } = renderHook(() => useIndexLink("spaceships"), {
116
- wrapper: createWrapper(undefined, queryClient),
116
+ wrapper: createWrapper(undefined, queryClient)
117
117
  });
118
118
  expect(result.current).toBe("/api/spaceships");
119
119
  });
@@ -131,12 +131,12 @@ describe("Test base api hooks", () => {
131
131
  version: "x.y.z",
132
132
  _links: {
133
133
  spaceships: {
134
- href: "/api/spaceships",
135
- },
136
- },
134
+ href: "/api/spaceships"
135
+ }
136
+ }
137
137
  });
138
138
  const { result } = renderHook(() => useIndexLinks(), {
139
- wrapper: createWrapper(undefined, queryClient),
139
+ wrapper: createWrapper(undefined, queryClient)
140
140
  });
141
141
  expect((result.current!.spaceships as Link).href).toBe("/api/spaceships");
142
142
  });
@@ -151,10 +151,10 @@ describe("Test base api hooks", () => {
151
151
  it("should return version", () => {
152
152
  const queryClient = new QueryClient();
153
153
  queryClient.setQueryData("index", {
154
- version: "x.y.z",
154
+ version: "x.y.z"
155
155
  });
156
156
  const { result } = renderHook(() => useVersion(), {
157
- wrapper: createWrapper(undefined, queryClient),
157
+ wrapper: createWrapper(undefined, queryClient)
158
158
  });
159
159
  expect(result.current).toBe("x.y.z");
160
160
  });
@@ -165,10 +165,10 @@ describe("Test base api hooks", () => {
165
165
  const queryClient = new QueryClient();
166
166
  queryClient.setQueryData("index", {
167
167
  version: "x.y.z",
168
- _links: {},
168
+ _links: {}
169
169
  });
170
170
  const { result } = renderHook(() => useRequiredIndexLink("spaceships"), {
171
- wrapper: createWrapper(undefined, queryClient),
171
+ wrapper: createWrapper(undefined, queryClient)
172
172
  });
173
173
  expect(result.error).toBeDefined();
174
174
  });
@@ -179,12 +179,12 @@ describe("Test base api hooks", () => {
179
179
  version: "x.y.z",
180
180
  _links: {
181
181
  spaceships: {
182
- href: "/api/spaceships",
183
- },
184
- },
182
+ href: "/api/spaceships"
183
+ }
184
+ }
185
185
  });
186
186
  const { result } = renderHook(() => useRequiredIndexLink("spaceships"), {
187
- wrapper: createWrapper(undefined, queryClient),
187
+ wrapper: createWrapper(undefined, queryClient)
188
188
  });
189
189
  expect(result.current).toBe("/api/spaceships");
190
190
  });
@@ -197,19 +197,19 @@ describe("Test base api hooks", () => {
197
197
  version: "x.y.z",
198
198
  _links: {
199
199
  spaceships: {
200
- href: "/spaceships",
201
- },
202
- },
200
+ href: "/spaceships"
201
+ }
202
+ }
203
203
  });
204
204
 
205
205
  const spaceship = {
206
- name: "heartOfGold",
206
+ name: "heartOfGold"
207
207
  };
208
208
 
209
209
  fetchMock.get("/api/v2/spaceships", spaceship);
210
210
 
211
211
  const { result, waitFor } = renderHook(() => useIndexJsonResource<typeof spaceship>("spaceships"), {
212
- wrapper: createWrapper(undefined, queryClient),
212
+ wrapper: createWrapper(undefined, queryClient)
213
213
  });
214
214
 
215
215
  await waitFor(() => {
@@ -224,11 +224,11 @@ describe("Test base api hooks", () => {
224
224
  const queryClient = new QueryClient();
225
225
  queryClient.setQueryData("index", {
226
226
  version: "x.y.z",
227
- _links: {},
227
+ _links: {}
228
228
  });
229
229
 
230
230
  const { result } = renderHook(() => useIndexJsonResource<{}>("spaceships"), {
231
- wrapper: createWrapper(undefined, queryClient),
231
+ wrapper: createWrapper(undefined, queryClient)
232
232
  });
233
233
 
234
234
  expect(result.current.isLoading).toBe(false);
@@ -36,9 +36,9 @@ describe("Test branches hooks", () => {
36
36
  type: "hg",
37
37
  _links: {
38
38
  branches: {
39
- href: "/hog/branches",
40
- },
41
- },
39
+ href: "/hog/branches"
40
+ }
41
+ }
42
42
  };
43
43
 
44
44
  const develop: Branch = {
@@ -47,9 +47,9 @@ describe("Test branches hooks", () => {
47
47
  lastCommitter: { name: "trillian" },
48
48
  _links: {
49
49
  delete: {
50
- href: "/hog/branches/develop",
51
- },
52
- },
50
+ href: "/hog/branches/develop"
51
+ }
52
+ }
53
53
  };
54
54
 
55
55
  const feature: Branch = {
@@ -58,16 +58,16 @@ describe("Test branches hooks", () => {
58
58
  lastCommitter: { name: "trillian" },
59
59
  _links: {
60
60
  delete: {
61
- href: "/hog/branches/feature%2Fsomething-special",
62
- },
63
- },
61
+ href: "/hog/branches/feature%2Fsomething-special"
62
+ }
63
+ }
64
64
  };
65
65
 
66
66
  const branches: BranchCollection = {
67
67
  _embedded: {
68
- branches: [develop],
68
+ branches: [develop]
69
69
  },
70
- _links: {},
70
+ _links: {}
71
71
  };
72
72
 
73
73
  const queryClient = createInfiniteCachingClient();
@@ -85,7 +85,7 @@ describe("Test branches hooks", () => {
85
85
  fetchMock.getOnce("/api/v2/hog/branches", branches);
86
86
 
87
87
  const { result, waitFor } = renderHook(() => useBranches(repository), {
88
- wrapper: createWrapper(undefined, queryClient),
88
+ wrapper: createWrapper(undefined, queryClient)
89
89
  });
90
90
  await waitFor(() => {
91
91
  return !!result.current.data;
@@ -106,7 +106,7 @@ describe("Test branches hooks", () => {
106
106
  "repository",
107
107
  "hitchhiker",
108
108
  "heart-of-gold",
109
- "branches",
109
+ "branches"
110
110
  ]);
111
111
  expect(data).toEqual(branches);
112
112
  });
@@ -117,7 +117,7 @@ describe("Test branches hooks", () => {
117
117
  fetchMock.getOnce("/api/v2/hog/branches/" + encodeURIComponent(name), branch);
118
118
 
119
119
  const { result, waitFor } = renderHook(() => useBranch(repository, name), {
120
- wrapper: createWrapper(undefined, queryClient),
120
+ wrapper: createWrapper(undefined, queryClient)
121
121
  });
122
122
 
123
123
  expect(result.error).toBeUndefined();
@@ -145,14 +145,14 @@ describe("Test branches hooks", () => {
145
145
  fetchMock.postOnce("/api/v2/hog/branches", {
146
146
  status: 201,
147
147
  headers: {
148
- Location: "/hog/branches/develop",
149
- },
148
+ Location: "/hog/branches/develop"
149
+ }
150
150
  });
151
151
 
152
152
  fetchMock.getOnce("/api/v2/hog/branches/develop", develop);
153
153
 
154
154
  const { result, waitForNextUpdate } = renderHook(() => useCreateBranch(repository), {
155
- wrapper: createWrapper(undefined, queryClient),
155
+ wrapper: createWrapper(undefined, queryClient)
156
156
  });
157
157
 
158
158
  await act(() => {
@@ -177,7 +177,7 @@ describe("Test branches hooks", () => {
177
177
  "hitchhiker",
178
178
  "heart-of-gold",
179
179
  "branch",
180
- "develop",
180
+ "develop"
181
181
  ]);
182
182
  expect(branch).toEqual(develop);
183
183
  });
@@ -194,11 +194,11 @@ describe("Test branches hooks", () => {
194
194
  describe("useDeleteBranch tests", () => {
195
195
  const deleteBranch = async () => {
196
196
  fetchMock.deleteOnce("/api/v2/hog/branches/develop", {
197
- status: 204,
197
+ status: 204
198
198
  });
199
199
 
200
200
  const { result, waitForNextUpdate } = renderHook(() => useDeleteBranch(repository), {
201
- wrapper: createWrapper(undefined, queryClient),
201
+ wrapper: createWrapper(undefined, queryClient)
202
202
  });
203
203
 
204
204
  await act(() => {