@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
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
ClientRequestInit,
|
|
5
|
+
FetchRequestInit,
|
|
6
|
+
IHttpClient,
|
|
7
|
+
JsonRequest,
|
|
8
8
|
} from '@equinor/fusion-framework-module-http/client';
|
|
9
9
|
|
|
10
10
|
import type { ClientMethod, ExtractApiVersion, FilterAllowedApiVersions } from '../types';
|
|
@@ -21,93 +21,93 @@ type AllowedVersions = FilterAllowedApiVersions<AvailableVersions>;
|
|
|
21
21
|
|
|
22
22
|
/** Schema for the input arguments to this operation. */
|
|
23
23
|
const ArgSchema = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
[ApiVersion.v1]: z.object({
|
|
25
|
+
bookmarkId: z.string(),
|
|
26
|
+
}),
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
/** Schema for the response from the API. */
|
|
30
30
|
const ApiResponseSchema = {
|
|
31
|
-
|
|
31
|
+
[ApiVersion.v1]: z.boolean(),
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
/** Defines the expected output from the api. */
|
|
35
35
|
type ApiResponse<TVersion extends AllowedVersions> = z.infer<
|
|
36
|
-
|
|
36
|
+
(typeof ApiResponseSchema)[ExtractApiVersion<TVersion>]
|
|
37
37
|
>;
|
|
38
38
|
|
|
39
39
|
/** Defines the input arguments to this operation. */
|
|
40
40
|
type MethodArg<TVersion extends AllowedVersions> = z.input<
|
|
41
|
-
|
|
41
|
+
(typeof ArgSchema)[ExtractApiVersion<TVersion>]
|
|
42
42
|
>;
|
|
43
43
|
|
|
44
44
|
/** Defines the expected output of this operation. */
|
|
45
45
|
type MethodResult<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
TVersion extends AllowedVersions,
|
|
47
|
+
TMethod extends keyof ClientMethod<unknown> = keyof ClientMethod<unknown>,
|
|
48
|
+
TResult = ApiResponse<TVersion>,
|
|
49
49
|
> = ClientMethod<TResult>[TMethod];
|
|
50
50
|
|
|
51
51
|
/** utility function for generating http request initialization parameters */
|
|
52
52
|
const generateRequestParameters = <TResult, TVersion extends AvailableVersions>(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
version: TVersion,
|
|
54
|
+
args: z.infer<(typeof ArgSchema)[TVersion]>,
|
|
55
|
+
init?: ClientRequestInit<IHttpClient, TResult>,
|
|
56
56
|
): ClientRequestInit<IHttpClient, TResult> => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
57
|
+
switch (version) {
|
|
58
|
+
case ApiVersion.v1: {
|
|
59
|
+
const baseInit: FetchRequestInit<ApiResponse<ApiVersion.v1>, JsonRequest> = {
|
|
60
|
+
method: 'HEAD',
|
|
61
|
+
selector: headSelector,
|
|
62
|
+
};
|
|
63
|
+
return Object.assign({}, baseInit, init);
|
|
65
64
|
}
|
|
66
|
-
|
|
65
|
+
}
|
|
66
|
+
throw Error(`Unknown API version: ${version}`);
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
/** utility function for generating the api path */
|
|
70
70
|
const generateApiPath = <TVersion extends AvailableVersions>(
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
version: TVersion,
|
|
72
|
+
args: z.infer<(typeof ArgSchema)[TVersion]>,
|
|
73
73
|
): string => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
74
|
+
switch (version) {
|
|
75
|
+
case ApiVersion.v1: {
|
|
76
|
+
const params = new URLSearchParams();
|
|
77
|
+
params.append('api-version', version);
|
|
78
|
+
return `/persons/me/bookmarks/favourites/${args.bookmarkId}?${String(params)}`;
|
|
80
79
|
}
|
|
81
|
-
|
|
80
|
+
}
|
|
81
|
+
throw Error(`Unknown API version: ${version}`);
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
/** executes the api call */
|
|
85
85
|
const executeApiCall = <TVersion extends AllowedVersions, TMethod extends keyof ClientMethod>(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
version: TVersion,
|
|
87
|
+
client: IHttpClient,
|
|
88
|
+
method: TMethod = 'json' as TMethod,
|
|
89
89
|
) => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
90
|
+
type MethodVersion = ExtractApiVersion<TVersion>;
|
|
91
|
+
const apiVersion = extractVersion(ApiVersion, version);
|
|
92
|
+
return <
|
|
93
|
+
TResponse = ApiResponse<MethodVersion>,
|
|
94
|
+
TResult = MethodResult<MethodVersion, TMethod, TResponse>,
|
|
95
|
+
>(
|
|
96
|
+
input: MethodArg<MethodVersion>,
|
|
97
|
+
init?: ClientRequestInit<IHttpClient, TResponse>,
|
|
98
|
+
): TResult => {
|
|
99
|
+
const args = ArgSchema[apiVersion].parse(input);
|
|
100
|
+
return client[method](
|
|
101
|
+
generateApiPath(apiVersion, args),
|
|
102
|
+
generateRequestParameters(apiVersion, args, init),
|
|
103
|
+
) as TResult;
|
|
104
|
+
};
|
|
105
105
|
};
|
|
106
106
|
|
|
107
107
|
export {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
type AllowedVersions as IsFavoriteBookmarkVersion,
|
|
109
|
+
type MethodArg as IsFavoriteBookmarkArgs,
|
|
110
|
+
type ApiResponse as IsFavoriteBookmarkResponse,
|
|
111
|
+
type MethodResult as IsFavoriteBookmarkResult,
|
|
112
|
+
executeApiCall as isFavoriteBookmark,
|
|
113
113
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
ClientRequestInit,
|
|
5
|
+
FetchRequestInit,
|
|
6
|
+
IHttpClient,
|
|
7
|
+
JsonRequest,
|
|
8
8
|
} from '@equinor/fusion-framework-module-http/client';
|
|
9
9
|
|
|
10
10
|
import type { ClientMethod, ExtractApiVersion, FilterAllowedApiVersions } from '../types';
|
|
@@ -21,94 +21,94 @@ type AllowedVersions = FilterAllowedApiVersions<AvailableVersions>;
|
|
|
21
21
|
|
|
22
22
|
/** Schema for the input arguments to this operation. */
|
|
23
23
|
const ArgSchema = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
[ApiVersion.v1]: z.object({
|
|
25
|
+
bookmarkId: z.string(),
|
|
26
|
+
}),
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
/** Schema for the response from the API. */
|
|
30
30
|
const ApiResponseSchema = {
|
|
31
|
-
|
|
31
|
+
[ApiVersion.v1]: z.boolean(),
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
/** Defines the expected output from the api. */
|
|
35
35
|
type ApiResponse<TVersion extends AllowedVersions> = z.infer<
|
|
36
|
-
|
|
36
|
+
(typeof ApiResponseSchema)[ExtractApiVersion<TVersion>]
|
|
37
37
|
>;
|
|
38
38
|
|
|
39
39
|
/** Defines the input arguments to this operation. */
|
|
40
40
|
type MethodArg<TVersion extends AllowedVersions> = z.input<
|
|
41
|
-
|
|
41
|
+
(typeof ArgSchema)[ExtractApiVersion<TVersion>]
|
|
42
42
|
>;
|
|
43
43
|
|
|
44
44
|
/** Defines the expected output of this operation. */
|
|
45
45
|
type MethodResult<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
TVersion extends AllowedVersions,
|
|
47
|
+
TMethod extends keyof ClientMethod<unknown> = keyof ClientMethod<unknown>,
|
|
48
|
+
TResult = ApiResponse<TVersion>,
|
|
49
49
|
> = ClientMethod<TResult>[TMethod];
|
|
50
50
|
|
|
51
51
|
/** utility function for generating http request initialization parameters */
|
|
52
52
|
const generateRequestParameters = <TResult, TVersion extends AvailableVersions>(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
version: TVersion,
|
|
54
|
+
args: z.infer<(typeof ArgSchema)[TVersion]>,
|
|
55
|
+
init?: ClientRequestInit<IHttpClient, TResult>,
|
|
56
56
|
): ClientRequestInit<IHttpClient, TResult> => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
57
|
+
switch (version) {
|
|
58
|
+
case ApiVersion.v1: {
|
|
59
|
+
const baseInit: FetchRequestInit<ApiResponse<ApiVersion.v1>, JsonRequest> = {
|
|
60
|
+
method: 'POST',
|
|
61
|
+
selector: statusSelector,
|
|
62
|
+
body: args,
|
|
63
|
+
};
|
|
64
|
+
return Object.assign({}, baseInit, init);
|
|
66
65
|
}
|
|
67
|
-
|
|
66
|
+
}
|
|
67
|
+
throw Error(`Unknown API version: ${version}`);
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
/** utility function for generating the api path */
|
|
71
71
|
const generateApiPath = <TVersion extends AvailableVersions>(
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
version: TVersion,
|
|
73
|
+
_args: z.infer<(typeof ArgSchema)[TVersion]>,
|
|
74
74
|
): string => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
75
|
+
switch (version) {
|
|
76
|
+
case ApiVersion.v1: {
|
|
77
|
+
const params = new URLSearchParams();
|
|
78
|
+
params.append('api-version', version);
|
|
79
|
+
return `/persons/me/bookmarks/favourites?${String(params)}`;
|
|
81
80
|
}
|
|
82
|
-
|
|
81
|
+
}
|
|
82
|
+
throw Error(`Unknown API version: ${version}`);
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
/** executes the api call */
|
|
86
86
|
const executeApiCall = <TVersion extends AllowedVersions, TMethod extends keyof ClientMethod>(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
version: TVersion,
|
|
88
|
+
client: IHttpClient,
|
|
89
|
+
method: TMethod = 'json' as TMethod,
|
|
90
90
|
) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
91
|
+
type MethodVersion = ExtractApiVersion<TVersion>;
|
|
92
|
+
const apiVersion = extractVersion(ApiVersion, version);
|
|
93
|
+
return <
|
|
94
|
+
TResponse = ApiResponse<MethodVersion>,
|
|
95
|
+
TResult = MethodResult<MethodVersion, TMethod, TResponse>,
|
|
96
|
+
>(
|
|
97
|
+
input: MethodArg<MethodVersion>,
|
|
98
|
+
init?: ClientRequestInit<IHttpClient, TResponse>,
|
|
99
|
+
): TResult => {
|
|
100
|
+
const args = ArgSchema[apiVersion].parse(input);
|
|
101
|
+
return client[method](
|
|
102
|
+
generateApiPath(apiVersion, args),
|
|
103
|
+
generateRequestParameters(apiVersion, args, init),
|
|
104
|
+
) as TResult;
|
|
105
|
+
};
|
|
106
106
|
};
|
|
107
107
|
|
|
108
108
|
export {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
type AllowedVersions as AddBookmarkFavouriteVersion,
|
|
110
|
+
type MethodArg as AddBookmarkFavouriteArgs,
|
|
111
|
+
type ApiResponse as AddBookmarkFavouriteResponse,
|
|
112
|
+
type MethodResult as AddBookmarkFavouriteResult,
|
|
113
|
+
executeApiCall as addBookmarkAsFavourite,
|
|
114
114
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
ClientRequestInit,
|
|
5
|
+
FetchRequestInit,
|
|
6
|
+
IHttpClient,
|
|
7
|
+
JsonRequest,
|
|
8
8
|
} from '@equinor/fusion-framework-module-http/client';
|
|
9
9
|
|
|
10
10
|
import type { ClientMethod, ExtractApiVersion, FilterAllowedApiVersions } from '../types';
|
|
@@ -25,142 +25,142 @@ type AllowedVersions = FilterAllowedApiVersions<AvailableVersions>;
|
|
|
25
25
|
* @todo This function should be moved to a shared utility module.
|
|
26
26
|
*/
|
|
27
27
|
const transformOdataFilter = (filter: Record<string, unknown>) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
28
|
+
return Object.entries(filter)
|
|
29
|
+
.map(([key, value]) => {
|
|
30
|
+
if (value === null) {
|
|
31
|
+
return `${key} eq null`;
|
|
32
|
+
}
|
|
33
|
+
if (typeof value === 'string') {
|
|
34
|
+
return `${key} eq '${value}'`;
|
|
35
|
+
}
|
|
36
|
+
if (typeof value === 'boolean') {
|
|
37
|
+
return `${key} eq ${value}`;
|
|
38
|
+
}
|
|
39
|
+
if (typeof value === 'object') {
|
|
40
|
+
return Object.entries(value)
|
|
41
|
+
.map(([subKey, subValue]) => `${key}.${subKey} eq '${subValue}'`)
|
|
42
|
+
.join(' and ');
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
.filter((x) => !!x)
|
|
46
|
+
.join(' and ');
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
const filterSchema_v1 = z
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
.object({
|
|
51
|
+
appKey: z.string().optional(),
|
|
52
|
+
contextId: z.string().optional(),
|
|
53
|
+
sourceSystem: ApiSourceSystem[ApiVersion.v1].partial().optional(),
|
|
54
|
+
})
|
|
55
|
+
.transform(transformOdataFilter);
|
|
56
56
|
|
|
57
57
|
const filterSchema_v2 = z
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
.object({
|
|
59
|
+
appKey: z.string().optional(),
|
|
60
|
+
contextId: z.string().optional(),
|
|
61
|
+
sourceSystem: ApiSourceSystem[ApiVersion.v1].partial().optional(),
|
|
62
|
+
isFavourite: z.boolean().optional(),
|
|
63
|
+
})
|
|
64
|
+
.transform(transformOdataFilter);
|
|
65
65
|
|
|
66
66
|
/** Schema for the input arguments to this operation. */
|
|
67
67
|
const ArgSchema = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
[ApiVersion.v1]: z
|
|
69
|
+
.object({
|
|
70
|
+
filter: z.string().or(filterSchema_v1).optional(),
|
|
71
|
+
})
|
|
72
|
+
.optional(),
|
|
73
|
+
[ApiVersion.v2]: z
|
|
74
|
+
.object({
|
|
75
|
+
filter: z.string().or(filterSchema_v2).optional(),
|
|
76
|
+
})
|
|
77
|
+
.optional(),
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
/** Schema for the response from the API. */
|
|
81
81
|
const ApiResponseSchema = {
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
[ApiVersion.v1]: z.array(ApiBookmarkSchema[ApiVersion.v1]),
|
|
83
|
+
[ApiVersion.v2]: z.array(ApiBookmarkSchema[ApiVersion.v2]),
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
/** Defines the expected output from the api. */
|
|
87
87
|
type ApiResponse<TVersion extends AllowedVersions> = z.infer<
|
|
88
|
-
|
|
88
|
+
(typeof ApiResponseSchema)[ExtractApiVersion<TVersion>]
|
|
89
89
|
>;
|
|
90
90
|
|
|
91
91
|
/** Defines the input arguments to this operation. */
|
|
92
92
|
type MethodArg<TVersion extends AllowedVersions> = z.input<
|
|
93
|
-
|
|
93
|
+
(typeof ArgSchema)[ExtractApiVersion<TVersion>]
|
|
94
94
|
>;
|
|
95
95
|
|
|
96
96
|
/** Defines the expected output of this operation. */
|
|
97
97
|
type MethodResult<
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
TVersion extends AllowedVersions,
|
|
99
|
+
TMethod extends keyof ClientMethod<unknown> = keyof ClientMethod<unknown>,
|
|
100
|
+
TResult = ApiResponse<TVersion>,
|
|
101
101
|
> = ClientMethod<TResult>[TMethod];
|
|
102
102
|
|
|
103
103
|
/** utility function for generating http request initialization parameters */
|
|
104
104
|
const generateRequestParameters = <TResult, TVersion extends AvailableVersions>(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
version: TVersion,
|
|
106
|
+
_args: z.infer<(typeof ArgSchema)[TVersion]>,
|
|
107
|
+
init?: ClientRequestInit<IHttpClient, TResult>,
|
|
108
108
|
): ClientRequestInit<IHttpClient, TResult> => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
109
|
+
switch (version) {
|
|
110
|
+
case ApiVersion.v1:
|
|
111
|
+
case ApiVersion.v2: {
|
|
112
|
+
const baseInit: FetchRequestInit<ApiResponse<ApiVersion.v1>, JsonRequest> = {
|
|
113
|
+
selector: schemaSelector(ApiResponseSchema[version]),
|
|
114
|
+
};
|
|
115
|
+
return Object.assign({}, baseInit, init);
|
|
117
116
|
}
|
|
118
|
-
|
|
117
|
+
}
|
|
118
|
+
throw Error(`Unknown API version: ${version}`);
|
|
119
119
|
};
|
|
120
120
|
|
|
121
121
|
/** utility function for generating the api path */
|
|
122
122
|
const generateApiPath = <TVersion extends AvailableVersions>(
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
version: TVersion,
|
|
124
|
+
args: z.infer<(typeof ArgSchema)[TVersion]>,
|
|
125
125
|
): string => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
126
|
+
switch (version) {
|
|
127
|
+
case ApiVersion.v1:
|
|
128
|
+
case ApiVersion.v2: {
|
|
129
|
+
const params = new URLSearchParams();
|
|
130
|
+
params.append('api-version', version);
|
|
131
|
+
args?.filter && params.append('$filter', args.filter);
|
|
132
|
+
return `/persons/me/bookmarks/?${String(params)}`;
|
|
134
133
|
}
|
|
135
|
-
|
|
134
|
+
}
|
|
135
|
+
throw Error(`Unknown API version: ${version}`);
|
|
136
136
|
};
|
|
137
137
|
|
|
138
138
|
/** executes the api call */
|
|
139
139
|
const executeApiCall = <TVersion extends AllowedVersions, TMethod extends keyof ClientMethod>(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
version: TVersion,
|
|
141
|
+
client: IHttpClient,
|
|
142
|
+
method: TMethod = 'json' as TMethod,
|
|
143
143
|
) => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
144
|
+
type MethodVersion = ExtractApiVersion<TVersion>;
|
|
145
|
+
const apiVersion = extractVersion(ApiVersion, version);
|
|
146
|
+
return <
|
|
147
|
+
TResponse = ApiResponse<MethodVersion>,
|
|
148
|
+
TResult = MethodResult<MethodVersion, TMethod, TResponse>,
|
|
149
|
+
>(
|
|
150
|
+
input: MethodArg<MethodVersion>,
|
|
151
|
+
init?: ClientRequestInit<IHttpClient, TResponse>,
|
|
152
|
+
): TResult => {
|
|
153
|
+
const args = ArgSchema[apiVersion].parse(input);
|
|
154
|
+
const path = generateApiPath(apiVersion, args);
|
|
155
|
+
const params = generateRequestParameters(apiVersion, args, init);
|
|
156
|
+
return client[method](path, params) as TResult;
|
|
157
|
+
};
|
|
158
158
|
};
|
|
159
159
|
|
|
160
160
|
export {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
type AllowedVersions as GetBookmarksVersion,
|
|
162
|
+
type MethodArg as GetBookmarksArgs,
|
|
163
|
+
type ApiResponse as GetBookmarksResponse,
|
|
164
|
+
type MethodResult as GetBookmarksResult,
|
|
165
|
+
executeApiCall as getBookmarks,
|
|
166
166
|
};
|