@equinor/fusion-framework-module-services 5.1.1-msal-6cf764b628c2afdd64dfd06e42abc953d78556d2 → 5.1.1
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/CHANGELOG.md +103 -98
- package/dist/esm/bookmarks/api-version.js.map +1 -1
- package/dist/esm/bookmarks/client.js.map +1 -1
- package/dist/esm/bookmarks/endpoints/bookmark-apply.get.js.map +1 -1
- package/dist/esm/bookmarks/endpoints/bookmark.delete.js.map +1 -1
- package/dist/esm/bookmarks/endpoints/bookmark.get.js.map +1 -1
- package/dist/esm/bookmarks/endpoints/bookmark.patch.js.map +1 -1
- package/dist/esm/bookmarks/endpoints/bookmark.post.js.map +1 -1
- package/dist/esm/bookmarks/endpoints/user-bookmark-favourite.delete.js.map +1 -1
- package/dist/esm/bookmarks/endpoints/user-bookmark-favourite.head.js.map +1 -1
- package/dist/esm/bookmarks/endpoints/user-bookmark-favourite.post.js.map +1 -1
- package/dist/esm/bookmarks/endpoints/user-bookmarks.get.js.map +1 -1
- package/dist/esm/bookmarks/schemas.js +1 -3
- package/dist/esm/bookmarks/schemas.js.map +1 -1
- package/dist/esm/bookmarks/selectors.js.map +1 -1
- package/dist/esm/context/client.js +2 -2
- package/dist/esm/context/client.js.map +1 -1
- package/dist/esm/context/get/client.js.map +1 -1
- package/dist/esm/context/get/generate-endpoint.js +0 -1
- package/dist/esm/context/get/generate-endpoint.js.map +1 -1
- package/dist/esm/context/get/generate-parameters.js.map +1 -1
- package/dist/esm/context/get/types.js.map +1 -1
- package/dist/esm/context/query/client.js.map +1 -1
- package/dist/esm/context/query/generate-endpoint.js +0 -1
- package/dist/esm/context/query/generate-endpoint.js.map +1 -1
- package/dist/esm/context/query/generate-parameters.js.map +1 -1
- package/dist/esm/context/query/types.js.map +1 -1
- package/dist/esm/context/related/client.js.map +1 -1
- package/dist/esm/context/related/generate-endpoint.js +0 -1
- package/dist/esm/context/related/generate-endpoint.js.map +1 -1
- package/dist/esm/context/related/generate-parameters.js.map +1 -1
- package/dist/esm/context/related/types.js.map +1 -1
- package/dist/esm/context/static.js.map +1 -1
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/notification/client.js.map +1 -1
- package/dist/esm/notification/notification/delete/client.js.map +1 -1
- package/dist/esm/notification/notification/delete/generate-endpoint.js +0 -1
- package/dist/esm/notification/notification/delete/generate-endpoint.js.map +1 -1
- package/dist/esm/notification/notification/delete/generate-parameters.js.map +1 -1
- package/dist/esm/notification/notification/get/client.js.map +1 -1
- package/dist/esm/notification/notification/get/generate-endpoint.js +0 -1
- package/dist/esm/notification/notification/get/generate-endpoint.js.map +1 -1
- package/dist/esm/notification/notification/get/generate-parameters.js.map +1 -1
- package/dist/esm/notification/notification/getAll/client.js.map +1 -1
- package/dist/esm/notification/notification/getAll/generate-endpoint.js +0 -1
- package/dist/esm/notification/notification/getAll/generate-endpoint.js.map +1 -1
- package/dist/esm/notification/notification/getAll/generate-parameters.js.map +1 -1
- package/dist/esm/notification/notification/patch/client.js.map +1 -1
- package/dist/esm/notification/notification/patch/generate-endpoint.js +0 -1
- package/dist/esm/notification/notification/patch/generate-endpoint.js.map +1 -1
- package/dist/esm/notification/notification/patch/generate-parameters.js.map +1 -1
- package/dist/esm/notification/notification/post/client.js.map +1 -1
- package/dist/esm/notification/notification/post/generate-endpoint.js +0 -1
- package/dist/esm/notification/notification/post/generate-endpoint.js.map +1 -1
- package/dist/esm/notification/notification/post/generate-parameters.js.map +1 -1
- package/dist/esm/notification/settings/get/client.js.map +1 -1
- package/dist/esm/notification/settings/get/generate-endpoint.js +0 -1
- package/dist/esm/notification/settings/get/generate-endpoint.js.map +1 -1
- package/dist/esm/notification/settings/get/generate-parameters.js.map +1 -1
- package/dist/esm/notification/settings/put/client.js.map +1 -1
- package/dist/esm/notification/settings/put/generate-endpoint.js +0 -1
- package/dist/esm/notification/settings/put/generate-endpoint.js.map +1 -1
- package/dist/esm/notification/settings/put/generate-parameters.js.map +1 -1
- package/dist/esm/notification/static.js.map +1 -1
- package/dist/esm/people/client.js.map +1 -1
- package/dist/esm/people/person-details/client.js.map +1 -1
- package/dist/esm/people/person-details/generate-endpoint.js.map +1 -1
- package/dist/esm/people/person-details/generate-parameters.js.map +1 -1
- package/dist/esm/people/person-photo/client.js.map +1 -1
- package/dist/esm/people/person-photo/generate-endpoint.js.map +1 -1
- package/dist/esm/people/person-photo/generate-parameters.js.map +1 -1
- package/dist/esm/people/query/client.js.map +1 -1
- package/dist/esm/people/query/generate-endpoint.js.map +1 -1
- package/dist/esm/people/query/generate-parameters.js.map +1 -1
- package/dist/esm/people/static.js.map +1 -1
- package/dist/esm/people/utils.js.map +1 -1
- package/dist/esm/provider.js.map +1 -1
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/bookmarks/api-version.d.ts +2 -2
- package/dist/types/bookmarks/client.d.ts +8 -8
- package/dist/types/bookmarks/endpoints/bookmark-apply.get.d.ts +1 -1
- package/dist/types/bookmarks/endpoints/bookmark.delete.d.ts +1 -1
- package/dist/types/bookmarks/endpoints/bookmark.get.d.ts +1 -1
- package/dist/types/bookmarks/endpoints/bookmark.patch.d.ts +1 -1
- package/dist/types/bookmarks/endpoints/bookmark.post.d.ts +1 -1
- package/dist/types/bookmarks/endpoints/user-bookmark-favourite.delete.d.ts +1 -1
- package/dist/types/bookmarks/endpoints/user-bookmark-favourite.head.d.ts +1 -1
- package/dist/types/bookmarks/endpoints/user-bookmark-favourite.post.d.ts +1 -1
- package/dist/types/bookmarks/endpoints/user-bookmarks.get.d.ts +1 -1
- package/dist/types/bookmarks/selectors.d.ts +1 -1
- package/dist/types/bookmarks/types.d.ts +1 -1
- package/dist/types/configurator.d.ts +1 -1
- package/dist/types/context/client.d.ts +4 -4
- package/dist/types/context/get/client.d.ts +1 -1
- package/dist/types/context/get/types.d.ts +2 -2
- package/dist/types/context/query/client.d.ts +1 -1
- package/dist/types/context/query/generate-parameters.d.ts +1 -1
- package/dist/types/context/query/types.d.ts +2 -2
- package/dist/types/context/related/client.d.ts +1 -1
- package/dist/types/context/related/generate-parameters.d.ts +1 -1
- package/dist/types/context/related/types.d.ts +2 -2
- package/dist/types/context/static.d.ts +2 -2
- package/dist/types/module.d.ts +2 -2
- package/dist/types/notification/client.d.ts +9 -9
- package/dist/types/notification/notification/delete/client.d.ts +2 -2
- package/dist/types/notification/notification/delete/generate-parameters.d.ts +2 -2
- package/dist/types/notification/notification/delete/types.d.ts +3 -3
- package/dist/types/notification/notification/get/client.d.ts +2 -2
- package/dist/types/notification/notification/get/generate-parameters.d.ts +2 -2
- package/dist/types/notification/notification/get/types.d.ts +3 -3
- package/dist/types/notification/notification/getAll/client.d.ts +2 -2
- package/dist/types/notification/notification/getAll/generate-parameters.d.ts +2 -2
- package/dist/types/notification/notification/getAll/types.d.ts +3 -3
- package/dist/types/notification/notification/patch/client.d.ts +2 -2
- package/dist/types/notification/notification/patch/generate-parameters.d.ts +2 -2
- package/dist/types/notification/notification/patch/types.d.ts +3 -3
- package/dist/types/notification/notification/post/client.d.ts +2 -2
- package/dist/types/notification/notification/post/generate-parameters.d.ts +2 -2
- package/dist/types/notification/notification/post/types.d.ts +3 -3
- package/dist/types/notification/settings/get/client.d.ts +2 -2
- package/dist/types/notification/settings/get/generate-parameters.d.ts +2 -2
- package/dist/types/notification/settings/get/types.d.ts +3 -3
- package/dist/types/notification/settings/put/client.d.ts +2 -2
- package/dist/types/notification/settings/put/generate-parameters.d.ts +2 -2
- package/dist/types/notification/settings/put/types.d.ts +3 -3
- package/dist/types/notification/static.d.ts +2 -2
- package/dist/types/people/api-models.d.ts +2 -2
- package/dist/types/people/api-models.v2.d.ts +1 -1
- package/dist/types/people/api-models.v4.d.ts +1 -1
- package/dist/types/people/client.d.ts +4 -4
- package/dist/types/people/person-details/client.d.ts +1 -1
- package/dist/types/people/person-details/types.d.ts +1 -1
- package/dist/types/people/person-photo/client.d.ts +1 -1
- package/dist/types/people/person-photo/types.d.ts +2 -2
- package/dist/types/people/query/client.d.ts +1 -1
- package/dist/types/people/query/types.d.ts +2 -2
- package/dist/types/people/static.d.ts +2 -2
- package/dist/types/people/utils.d.ts +1 -1
- package/dist/types/provider.d.ts +3 -3
- package/dist/types/types.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +5 -5
- package/src/bookmarks/api-version.ts +2 -2
- package/src/bookmarks/client.ts +228 -231
- package/src/bookmarks/endpoints/bookmark-apply.get.ts +58 -58
- package/src/bookmarks/endpoints/bookmark.delete.ts +57 -57
- package/src/bookmarks/endpoints/bookmark.get.ts +62 -62
- package/src/bookmarks/endpoints/bookmark.patch.ts +78 -78
- package/src/bookmarks/endpoints/bookmark.post.ts +68 -68
- package/src/bookmarks/endpoints/user-bookmark-favourite.delete.ts +57 -57
- package/src/bookmarks/endpoints/user-bookmark-favourite.head.ts +57 -57
- package/src/bookmarks/endpoints/user-bookmark-favourite.post.ts +58 -58
- package/src/bookmarks/endpoints/user-bookmarks.get.ts +98 -98
- package/src/bookmarks/schemas.ts +54 -56
- package/src/bookmarks/selectors.ts +24 -24
- package/src/bookmarks/types.ts +6 -6
- package/src/configurator.ts +3 -3
- package/src/context/api-models.ts +19 -19
- package/src/context/client.ts +68 -58
- package/src/context/get/client.ts +18 -18
- package/src/context/get/generate-endpoint.ts +13 -14
- package/src/context/get/generate-parameters.ts +9 -9
- package/src/context/get/types.ts +20 -20
- package/src/context/query/client.ts +22 -22
- package/src/context/query/generate-endpoint.ts +43 -44
- package/src/context/query/generate-parameters.ts +10 -10
- package/src/context/query/types.ts +25 -25
- package/src/context/related/client.ts +22 -22
- package/src/context/related/generate-endpoint.ts +40 -41
- package/src/context/related/generate-parameters.ts +10 -10
- package/src/context/related/types.ts +27 -27
- package/src/context/static.ts +3 -3
- package/src/errors.ts +6 -6
- package/src/module.ts +50 -52
- package/src/notification/api-models.ts +36 -36
- package/src/notification/client.ts +131 -151
- package/src/notification/notification/delete/client.ts +22 -22
- package/src/notification/notification/delete/generate-endpoint.ts +13 -14
- package/src/notification/notification/delete/generate-parameters.ts +18 -18
- package/src/notification/notification/delete/types.ts +21 -21
- package/src/notification/notification/get/client.ts +19 -19
- package/src/notification/notification/get/generate-endpoint.ts +13 -14
- package/src/notification/notification/get/generate-parameters.ts +11 -11
- package/src/notification/notification/get/types.ts +21 -21
- package/src/notification/notification/getAll/client.ts +22 -22
- package/src/notification/notification/getAll/generate-endpoint.ts +13 -14
- package/src/notification/notification/getAll/generate-parameters.ts +11 -11
- package/src/notification/notification/getAll/types.ts +21 -21
- package/src/notification/notification/patch/client.ts +22 -22
- package/src/notification/notification/patch/generate-endpoint.ts +13 -14
- package/src/notification/notification/patch/generate-parameters.ts +18 -18
- package/src/notification/notification/patch/types.ts +22 -22
- package/src/notification/notification/post/client.ts +22 -22
- package/src/notification/notification/post/generate-endpoint.ts +13 -14
- package/src/notification/notification/post/generate-parameters.ts +18 -18
- package/src/notification/notification/post/types.ts +31 -31
- package/src/notification/settings/get/client.ts +22 -22
- package/src/notification/settings/get/generate-endpoint.ts +13 -14
- package/src/notification/settings/get/generate-parameters.ts +11 -11
- package/src/notification/settings/get/types.ts +21 -21
- package/src/notification/settings/put/client.ts +22 -22
- package/src/notification/settings/put/generate-endpoint.ts +13 -14
- package/src/notification/settings/put/generate-parameters.ts +20 -20
- package/src/notification/settings/put/types.ts +20 -20
- package/src/notification/static.ts +3 -3
- package/src/people/api-models.ts +30 -30
- package/src/people/api-models.v2.ts +27 -27
- package/src/people/api-models.v4.ts +79 -79
- package/src/people/client.ts +73 -77
- package/src/people/person-details/client.ts +21 -18
- package/src/people/person-details/generate-endpoint.ts +16 -16
- package/src/people/person-details/generate-parameters.ts +8 -8
- package/src/people/person-details/types.ts +13 -13
- package/src/people/person-photo/client.ts +19 -22
- package/src/people/person-photo/generate-endpoint.ts +13 -13
- package/src/people/person-photo/generate-parameters.ts +8 -8
- package/src/people/person-photo/types.ts +8 -8
- package/src/people/query/client.ts +20 -18
- package/src/people/query/generate-endpoint.ts +14 -14
- package/src/people/query/generate-parameters.ts +8 -8
- package/src/people/query/types.ts +10 -10
- package/src/people/static.ts +2 -2
- package/src/people/utils.ts +20 -20
- package/src/provider.ts +85 -85
- package/src/types.ts +34 -34
- package/src/utils.ts +22 -26
- package/src/version.ts +1 -1
package/src/provider.ts
CHANGED
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
import { IHttpClient } from '@equinor/fusion-framework-module-http';
|
|
2
|
-
import { ClientMethod } from './types';
|
|
1
|
+
import type { IHttpClient } from '@equinor/fusion-framework-module-http';
|
|
2
|
+
import type { ClientMethod } from './types';
|
|
3
3
|
|
|
4
|
-
import { ApiClientFactory } from './types';
|
|
4
|
+
import type { ApiClientFactory } from './types';
|
|
5
5
|
import { ContextApiClient } from './context';
|
|
6
6
|
import BookmarksApiClient from './bookmarks/client';
|
|
7
7
|
import { NotificationApiClient } from './notification';
|
|
8
8
|
import { PeopleApiClient } from './people/client';
|
|
9
9
|
|
|
10
10
|
export interface IApiProvider<TClient extends IHttpClient = IHttpClient> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
/**
|
|
12
|
+
* @param method - Version of the service to use
|
|
13
|
+
*/
|
|
14
|
+
createBookmarksClient<TMethod extends keyof ClientMethod>(
|
|
15
|
+
method: TMethod,
|
|
16
|
+
): Promise<BookmarksApiClient<TMethod, TClient>>;
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
/**
|
|
19
|
+
* @param method - Version of the service to use
|
|
20
|
+
*/
|
|
21
|
+
createContextClient<TMethod extends keyof ClientMethod>(
|
|
22
|
+
method: TMethod,
|
|
23
|
+
): Promise<ContextApiClient<TMethod, TClient>>;
|
|
24
|
+
/**
|
|
25
|
+
* @param method - Version of the service to use
|
|
26
|
+
*/
|
|
27
|
+
createNotificationClient<TMethod extends keyof ClientMethod>(
|
|
28
|
+
method: TMethod,
|
|
29
|
+
): Promise<NotificationApiClient<TMethod, TClient>>;
|
|
30
|
+
/**
|
|
31
|
+
* @param method - Version of the service to use
|
|
32
|
+
*/
|
|
33
|
+
createPeopleClient(): Promise<PeopleApiClient<TClient>>;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
type ApiProviderCtorArgs<TClient extends IHttpClient = IHttpClient> = {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
/** method for creating IHttpClients for api clients */
|
|
38
|
+
createClient: ApiClientFactory<TClient>;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
// TODO move to own file
|
|
42
42
|
type ApiProviderErrorResponse = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
type: ResponseType;
|
|
44
|
+
status: number;
|
|
45
|
+
statusText: string;
|
|
46
|
+
headers: Headers;
|
|
47
|
+
url: string;
|
|
48
|
+
data: unknown;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
// TODO move to own file
|
|
52
52
|
export class ApiProviderError extends Error {
|
|
53
|
-
|
|
53
|
+
readonly response: ApiProviderErrorResponse;
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
constructor(msg: string, response: ApiProviderErrorResponse, options?: ErrorOptions) {
|
|
56
|
+
super(msg, options);
|
|
57
|
+
this.response = response;
|
|
58
|
+
this.name = 'ApiProviderError';
|
|
59
|
+
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
// TODO move to own file
|
|
63
63
|
const validateResponse = async (response: Response) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
const { headers, status, statusText, type, url, bodyUsed } = response;
|
|
66
|
+
const isJson = headers.get('content-type')?.match(/application\/(\w*)?[+]?json/);
|
|
67
|
+
const data = !bodyUsed && (await (isJson ? response.json() : response.text()));
|
|
68
|
+
throw new ApiProviderError('failed to execute request, response was not ok', {
|
|
69
|
+
headers,
|
|
70
|
+
status,
|
|
71
|
+
statusText,
|
|
72
|
+
type,
|
|
73
|
+
url,
|
|
74
|
+
data,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
export class ApiProvider<TClient extends IHttpClient = IHttpClient>
|
|
80
|
-
|
|
80
|
+
implements IApiProvider<TClient>
|
|
81
81
|
{
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
protected _createClientFn: ApiClientFactory<TClient>;
|
|
83
|
+
constructor({ createClient }: ApiProviderCtorArgs<TClient>) {
|
|
84
|
+
this._createClientFn = createClient;
|
|
85
|
+
}
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
public async createNotificationClient<TMethod extends keyof ClientMethod>(
|
|
88
|
+
method: TMethod,
|
|
89
|
+
): Promise<NotificationApiClient<TMethod, TClient>> {
|
|
90
|
+
const httpClient = await this._createClientFn('notification');
|
|
91
|
+
httpClient.responseHandler.add('validate_api_request', validateResponse);
|
|
92
|
+
return new NotificationApiClient(httpClient, method);
|
|
93
|
+
}
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
95
|
+
public async createBookmarksClient<TMethod extends keyof ClientMethod>(
|
|
96
|
+
method: TMethod,
|
|
97
|
+
): Promise<BookmarksApiClient<TMethod, TClient>> {
|
|
98
|
+
const httpClient = await this._createClientFn('bookmarks');
|
|
99
|
+
// TODO: update when new ResponseOperator is available
|
|
100
|
+
// will fail because 'HEAD' will return 404 when no bookmarks are found
|
|
101
|
+
// httpClient.responseHandler.add('validate_api_request', validateResponse);
|
|
102
|
+
return new BookmarksApiClient(httpClient, method);
|
|
103
|
+
}
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
105
|
+
public async createContextClient<TMethod extends keyof ClientMethod>(
|
|
106
|
+
method: TMethod,
|
|
107
|
+
): Promise<ContextApiClient<TMethod, TClient>> {
|
|
108
|
+
const httpClient = await this._createClientFn('context');
|
|
109
|
+
httpClient.responseHandler.add('validate_api_request', validateResponse);
|
|
110
|
+
return new ContextApiClient(httpClient, method);
|
|
111
|
+
}
|
|
112
|
+
public async createPeopleClient(): Promise<PeopleApiClient<TClient>> {
|
|
113
|
+
const httpClient = await this._createClientFn('people');
|
|
114
|
+
httpClient.responseHandler.add('validate_api_request', validateResponse);
|
|
115
|
+
return new PeopleApiClient(httpClient);
|
|
116
|
+
}
|
|
117
117
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type {
|
|
2
|
+
ClientRequestInit,
|
|
3
|
+
IHttpClient,
|
|
4
|
+
StreamResponse,
|
|
5
|
+
BlobResult,
|
|
6
6
|
} from '@equinor/fusion-framework-module-http/client';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
* @returns A Promise that resolves to an instance of the HTTP client.
|
|
13
13
|
*/
|
|
14
14
|
export type ApiClientFactory<TClient extends IHttpClient = IHttpClient> = (
|
|
15
|
-
|
|
15
|
+
name: string,
|
|
16
16
|
) => Promise<TClient>;
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -24,27 +24,27 @@ export type ApiClientFactory<TClient extends IHttpClient = IHttpClient> = (
|
|
|
24
24
|
* @param init - Optional initialization options for the API client request.
|
|
25
25
|
*/
|
|
26
26
|
export type ApiClientArguments<TClient extends IHttpClient, TResult = unknown> = [
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
path: string,
|
|
28
|
+
init?: ClientRequestInit<TClient, TResult>,
|
|
29
29
|
];
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Execute methods on the IHttpClient
|
|
33
33
|
*/
|
|
34
34
|
export type ClientMethod<T = unknown> = {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Fetch JSON data from a service
|
|
37
|
+
*/
|
|
38
|
+
json: Promise<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Fetch JSON data from a service as observable
|
|
41
|
+
*/
|
|
42
|
+
json$: StreamResponse<T>;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
export type ClientDataMethod<T extends BlobResult = BlobResult> = {
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
blob: Promise<T>;
|
|
47
|
+
blob$: StreamResponse<T>;
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
export type ClientMethodType = keyof ClientMethod;
|
|
@@ -97,16 +97,16 @@ export type ClientMethodType = keyof ClientMethod;
|
|
|
97
97
|
* values are a subset of `AllowedTypes`.
|
|
98
98
|
*/
|
|
99
99
|
export type FilterAllowedApiVersions<
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
TAvailableTypes extends Record<string, string>,
|
|
101
|
+
TAllowedTypes extends string | number | symbol = keyof TAvailableTypes,
|
|
102
102
|
> = {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
[K in keyof TAvailableTypes]: TAvailableTypes extends Record<K, infer V>
|
|
104
|
+
? K extends TAllowedTypes
|
|
105
|
+
? K | V
|
|
106
|
+
: V extends TAllowedTypes
|
|
107
|
+
? V | K
|
|
108
|
+
: never
|
|
109
|
+
: never;
|
|
110
110
|
}[keyof TAvailableTypes];
|
|
111
111
|
|
|
112
112
|
/**
|
|
@@ -118,11 +118,11 @@ export type FilterAllowedApiVersions<
|
|
|
118
118
|
* @returns The API version type if it is available and allowed, otherwise `never`.
|
|
119
119
|
*/
|
|
120
120
|
export type ExtractApiVersion<
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
TAvailableTypes extends Record<string, string>,
|
|
122
|
+
TVersion extends string,
|
|
123
|
+
TAllowedTypes extends string | number | symbol = FilterAllowedApiVersions<TAvailableTypes>,
|
|
124
124
|
> = TVersion extends keyof TAvailableTypes
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
? TAvailableTypes[TVersion]
|
|
126
|
+
: TVersion extends TAllowedTypes
|
|
127
|
+
? TVersion
|
|
128
|
+
: never;
|
package/src/utils.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
1
|
+
import type { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
import { FetchResponse } from '@equinor/fusion-framework-module-http';
|
|
3
|
+
import type { FetchResponse } from '@equinor/fusion-framework-module-http';
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
type ResponseSelector,
|
|
6
|
+
jsonSelector,
|
|
7
7
|
} from '@equinor/fusion-framework-module-http/selectors';
|
|
8
8
|
|
|
9
9
|
import type { ExtractApiVersion } from './types';
|
|
@@ -16,25 +16,21 @@ import type { ExtractApiVersion } from './types';
|
|
|
16
16
|
* @returns The extracted API version, or throws an error if the version is not supported.
|
|
17
17
|
*/
|
|
18
18
|
export const extractVersion = <
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
TApiVersions extends Record<string, string>,
|
|
20
|
+
TAllowedApiVersion extends string,
|
|
21
|
+
TVersion extends string,
|
|
22
22
|
>(
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
apiVersions: TApiVersions,
|
|
24
|
+
version: TVersion,
|
|
25
25
|
): ExtractApiVersion<TApiVersions, TVersion, TAllowedApiVersion> => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (!extractedVersion) {
|
|
35
|
-
throw new Error(`Version ${version} is not supported`);
|
|
36
|
-
}
|
|
37
|
-
return extractedVersion as ExtractApiVersion<TApiVersions, TVersion, TAllowedApiVersion>;
|
|
26
|
+
if (version in apiVersions) {
|
|
27
|
+
return apiVersions[version] as ExtractApiVersion<TApiVersions, TVersion, TAllowedApiVersion>;
|
|
28
|
+
}
|
|
29
|
+
const extractedVersion = Object.values(apiVersions).find((v) => v === version);
|
|
30
|
+
if (!extractedVersion) {
|
|
31
|
+
throw new Error(`Version ${version} is not supported`);
|
|
32
|
+
}
|
|
33
|
+
return extractedVersion as ExtractApiVersion<TApiVersions, TVersion, TAllowedApiVersion>;
|
|
38
34
|
};
|
|
39
35
|
|
|
40
36
|
/**
|
|
@@ -44,8 +40,8 @@ export const extractVersion = <
|
|
|
44
40
|
* @returns A response selector function that parses the response body using the provided schema.
|
|
45
41
|
*/
|
|
46
42
|
export const schemaSelector =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
<Output, Def extends z.ZodTypeDef, Input>(
|
|
44
|
+
schema: z.ZodSchema<Output, Def, Input>,
|
|
45
|
+
): ResponseSelector<Output> =>
|
|
46
|
+
async (response: FetchResponse<Input>) =>
|
|
47
|
+
schema.parse(await jsonSelector(response));
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '5.1.
|
|
2
|
+
export const version = '5.1.1';
|