@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,35 +1,35 @@
|
|
|
1
|
-
import { ClientRequestInit, IHttpClient } from '@equinor/fusion-framework-module-http/client';
|
|
1
|
+
import type { ClientRequestInit, IHttpClient } from '@equinor/fusion-framework-module-http/client';
|
|
2
2
|
|
|
3
|
-
import { ApiVersion } from '..';
|
|
3
|
+
import type { ApiVersion } from '..';
|
|
4
4
|
|
|
5
5
|
import { generateParameters } from './generate-parameters';
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
QueryContextArgs,
|
|
9
|
+
QueryContextResponse,
|
|
10
|
+
QueryContextResult,
|
|
11
|
+
ClientMethod,
|
|
12
12
|
} from './types';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Function for querying the context service
|
|
16
16
|
*/
|
|
17
17
|
export const queryContext =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
<
|
|
19
|
+
TVersion extends string = keyof typeof ApiVersion,
|
|
20
|
+
TMethod extends keyof ClientMethod = keyof ClientMethod,
|
|
21
|
+
TClient extends IHttpClient = IHttpClient,
|
|
22
|
+
>(
|
|
23
|
+
client: TClient,
|
|
24
|
+
version: TVersion,
|
|
25
|
+
method: TMethod = 'json' as TMethod,
|
|
26
|
+
) =>
|
|
27
|
+
<T = QueryContextResponse<TVersion>>(
|
|
28
|
+
args: QueryContextArgs<TVersion>,
|
|
29
|
+
init?: ClientRequestInit<TClient, T>,
|
|
30
|
+
): QueryContextResult<TVersion, TMethod, T> =>
|
|
31
|
+
client[method](
|
|
32
|
+
...generateParameters<T, TVersion, TClient>(version, args, init),
|
|
33
|
+
) as QueryContextResult<TVersion, TMethod, T>;
|
|
34
34
|
|
|
35
35
|
export default queryContext;
|
|
@@ -5,63 +5,62 @@ import { UnsupportedApiVersion } from '../../errors';
|
|
|
5
5
|
import { ApiVersion } from '..';
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
QueryContextArgs,
|
|
9
|
+
QueryContextOdataFilter,
|
|
10
|
+
QueryContextOdataParameters,
|
|
11
11
|
} from './types';
|
|
12
12
|
|
|
13
13
|
const buildOdataFilter = (filterObj: QueryContextOdataFilter) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
return Object.keys(filterObj).reduce((acc, key) => {
|
|
15
|
+
switch (key) {
|
|
16
|
+
case 'type':
|
|
17
|
+
return filterObj[key]?.length ? { ...acc, [key]: { in: filterObj[key] } } : acc;
|
|
18
|
+
default:
|
|
19
|
+
return { ...acc, [key]: filterObj[key as keyof typeof filterObj] };
|
|
20
|
+
}
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
}, {} as any);
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
const buildOdataObject = (parameters: QueryContextOdataParameters) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
return Object.entries(parameters)
|
|
27
|
+
.filter(([_, value]) => !!value)
|
|
28
|
+
.reduce((acc, [key, value]) => {
|
|
29
|
+
switch (key) {
|
|
30
|
+
case 'filter':
|
|
31
|
+
return {
|
|
32
|
+
...acc,
|
|
33
|
+
[key]: buildOdataFilter(value as QueryContextOdataFilter),
|
|
34
|
+
};
|
|
35
|
+
default:
|
|
36
|
+
return { ...acc, [key]: parameters[key as keyof typeof parameters] };
|
|
37
|
+
}
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
}, {} as any);
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
const createSearchParameters = (args: string | QueryContextOdataParameters) => {
|
|
43
|
-
|
|
43
|
+
return typeof args === 'string' ? args : buildOdataQuery(buildOdataObject(args));
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
export const generateEndpoint = <TVersion extends string = keyof typeof ApiVersion>(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return `/contexts/?${String(params)}`;
|
|
63
|
-
}
|
|
47
|
+
version: TVersion,
|
|
48
|
+
args: QueryContextArgs<TVersion>,
|
|
49
|
+
): string => {
|
|
50
|
+
const apiVersion = ApiVersion[version as keyof typeof ApiVersion] ?? version;
|
|
51
|
+
switch (apiVersion) {
|
|
52
|
+
case ApiVersion.v2:
|
|
53
|
+
throw new UnsupportedApiVersion(version);
|
|
54
|
+
default: {
|
|
55
|
+
const { query, includeDeleted } = args as QueryContextArgs<'v1'>;
|
|
56
|
+
const params = new URLSearchParams(createSearchParameters(query));
|
|
57
|
+
params.append('api-version', apiVersion);
|
|
58
|
+
if (includeDeleted) {
|
|
59
|
+
params.append('includeDeleted', 'true');
|
|
60
|
+
}
|
|
61
|
+
return `/contexts/?${String(params)}`;
|
|
64
62
|
}
|
|
63
|
+
}
|
|
65
64
|
};
|
|
66
65
|
|
|
67
66
|
export default generateEndpoint;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ClientRequestInit, IHttpClient } from '@equinor/fusion-framework-module-http/client';
|
|
1
|
+
import type { ClientRequestInit, IHttpClient } from '@equinor/fusion-framework-module-http/client';
|
|
2
2
|
|
|
3
|
-
import { ApiVersion } from '..';
|
|
3
|
+
import type { ApiVersion } from '..';
|
|
4
4
|
|
|
5
5
|
import { generateEndpoint } from './generate-endpoint';
|
|
6
6
|
|
|
@@ -8,16 +8,16 @@ import type { QueryContextArgs, ApiClientArguments } from './types';
|
|
|
8
8
|
|
|
9
9
|
/** Function for generating parameter for querying context service */
|
|
10
10
|
export const generateParameters = <
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
TResult,
|
|
12
|
+
TVersion extends string = keyof typeof ApiVersion,
|
|
13
|
+
TClient extends IHttpClient = IHttpClient,
|
|
14
14
|
>(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
version: TVersion,
|
|
16
|
+
args: QueryContextArgs<TVersion>,
|
|
17
|
+
init?: ClientRequestInit<TClient, TResult>,
|
|
18
18
|
): ApiClientArguments<TClient, TResult> => {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const path = generateEndpoint(version, args);
|
|
20
|
+
return [path, init];
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export default generateParameters;
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { IHttpClient, ClientRequestInit } from '@equinor/fusion-framework-module-http/client';
|
|
1
|
+
import type { IHttpClient, ClientRequestInit } from '@equinor/fusion-framework-module-http/client';
|
|
2
2
|
|
|
3
|
-
import { ApiVersion, ApiContextEntity, ClientMethod } from '..';
|
|
3
|
+
import { ApiVersion, type ApiContextEntity, type ClientMethod } from '..';
|
|
4
4
|
|
|
5
5
|
export { ApiClientArguments, ClientMethod } from '..';
|
|
6
6
|
|
|
7
7
|
export type QueryContextOdataFilter = {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
type?: string[];
|
|
9
|
+
externalId?: string;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export type QueryContextOdataParameters = {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
search?: string;
|
|
14
|
+
filter?: QueryContextOdataFilter;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
type QueryContextArgs_v1 = {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
query: string | QueryContextOdataParameters;
|
|
19
|
+
includeDeleted?: boolean;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
type QueryContextArgs_v2 = QueryContextArgs_v1;
|
|
23
23
|
|
|
24
24
|
type SearchContextArgTypes = {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
[ApiVersion.v1]: QueryContextArgs_v1;
|
|
26
|
+
[ApiVersion.v2]: QueryContextArgs_v2;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
export type QueryContextArgs<T> = T extends keyof typeof ApiVersion
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
? SearchContextArgTypes[(typeof ApiVersion)[T]]
|
|
31
|
+
: { query: { search: string } };
|
|
32
32
|
|
|
33
33
|
type QueryContextResponseTypes = {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
[ApiVersion.v1]: Array<ApiContextEntity<ApiVersion.v1>>;
|
|
35
|
+
[ApiVersion.v2]: Array<ApiContextEntity<ApiVersion.v2>>;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
export type QueryContextResponse<T> = T extends keyof typeof ApiVersion
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
? QueryContextResponseTypes[(typeof ApiVersion)[T]]
|
|
40
|
+
: unknown;
|
|
41
41
|
|
|
42
42
|
export type QueryContextFn<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
TVersion extends string = keyof typeof ApiVersion,
|
|
44
|
+
TMethod extends keyof ClientMethod<unknown> = keyof ClientMethod<unknown>,
|
|
45
|
+
TClient extends IHttpClient = IHttpClient,
|
|
46
|
+
TResult = QueryContextResponse<TVersion>,
|
|
47
47
|
> = (
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
args: QueryContextArgs<TVersion>,
|
|
49
|
+
init?: ClientRequestInit<TClient, TResult>,
|
|
50
50
|
) => QueryContextResult<TVersion, TMethod, TResult>;
|
|
51
51
|
|
|
52
52
|
export type QueryContextResult<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
TVersion extends string = keyof typeof ApiVersion,
|
|
54
|
+
TMethod extends keyof ClientMethod<unknown> = keyof ClientMethod<unknown>,
|
|
55
|
+
TResult = QueryContextResponse<TVersion>,
|
|
56
56
|
> = ClientMethod<TResult>[TMethod];
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { ClientRequestInit, IHttpClient } from '@equinor/fusion-framework-module-http/client';
|
|
1
|
+
import type { ClientRequestInit, IHttpClient } from '@equinor/fusion-framework-module-http/client';
|
|
2
2
|
|
|
3
|
-
import { ApiVersion } from '..';
|
|
3
|
+
import type { ApiVersion } from '..';
|
|
4
4
|
|
|
5
5
|
import { generateParameters } from './generate-parameters';
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
RelatedContextArgs,
|
|
9
|
+
RelatedContextResponse,
|
|
10
|
+
RelatedContextResult,
|
|
11
|
+
ClientMethod,
|
|
12
12
|
} from './types';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Function for querying the context service
|
|
16
16
|
*/
|
|
17
17
|
export const relatedContexts =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
<
|
|
19
|
+
TVersion extends string = keyof typeof ApiVersion,
|
|
20
|
+
TMethod extends keyof ClientMethod = keyof ClientMethod,
|
|
21
|
+
TClient extends IHttpClient = IHttpClient,
|
|
22
|
+
>(
|
|
23
|
+
client: TClient,
|
|
24
|
+
version: TVersion,
|
|
25
|
+
method: TMethod = 'json' as TMethod,
|
|
26
|
+
) =>
|
|
27
|
+
<T = RelatedContextResponse<TVersion>>(
|
|
28
|
+
args: RelatedContextArgs<TVersion>,
|
|
29
|
+
init?: ClientRequestInit<TClient, T>,
|
|
30
|
+
): RelatedContextResult<TVersion, TMethod, T> =>
|
|
31
|
+
client[method](
|
|
32
|
+
...generateParameters<T, TVersion, TClient>(version, args, init),
|
|
33
|
+
) as RelatedContextResult<TVersion, TMethod, T>;
|
|
34
34
|
|
|
35
35
|
export default relatedContexts;
|
|
@@ -5,59 +5,58 @@ import { UnsupportedApiVersion } from '../../errors';
|
|
|
5
5
|
import { ApiVersion } from '..';
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
RelatedContextArgs,
|
|
9
|
+
RelatedContextOdataFilter,
|
|
10
|
+
RelatedContextOdataParameters,
|
|
11
11
|
} from './types';
|
|
12
12
|
|
|
13
13
|
const buildOdataFilter = (filterObj: RelatedContextOdataFilter) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
return Object.keys(filterObj).reduce((acc, key) => {
|
|
15
|
+
switch (key) {
|
|
16
|
+
case 'type':
|
|
17
|
+
return filterObj[key]?.length ? { ...acc, [key]: { in: filterObj[key] } } : acc;
|
|
18
|
+
default:
|
|
19
|
+
return { ...acc, [key]: filterObj[key as keyof typeof filterObj] };
|
|
20
|
+
}
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
}, {} as any);
|
|
23
23
|
};
|
|
24
24
|
const buildOdataObject = (parameters: RelatedContextOdataParameters) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
return Object.entries(parameters)
|
|
26
|
+
.filter(([_, value]) => !!value)
|
|
27
|
+
.reduce((acc, [key, value]) => {
|
|
28
|
+
switch (key) {
|
|
29
|
+
case 'filter':
|
|
30
|
+
return {
|
|
31
|
+
...acc,
|
|
32
|
+
[key]: buildOdataFilter(value as RelatedContextOdataFilter),
|
|
33
|
+
};
|
|
34
|
+
default:
|
|
35
|
+
return { ...acc, [key]: parameters[key as keyof typeof parameters] };
|
|
36
|
+
}
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
}, {} as any);
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
const createSearchParameters = (args: string | RelatedContextOdataParameters) => {
|
|
42
|
-
|
|
42
|
+
return typeof args === 'string' ? args : buildOdataQuery(buildOdataObject(args));
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
export const generateEndpoint = <TVersion extends string = keyof typeof ApiVersion>(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return `/contexts/${id}/relations?${String(params)}`;
|
|
59
|
-
}
|
|
46
|
+
version: TVersion,
|
|
47
|
+
args: RelatedContextArgs<TVersion>,
|
|
48
|
+
): string => {
|
|
49
|
+
const apiVersion = ApiVersion[version as keyof typeof ApiVersion] ?? version;
|
|
50
|
+
switch (apiVersion) {
|
|
51
|
+
case ApiVersion.v2:
|
|
52
|
+
throw new UnsupportedApiVersion(version);
|
|
53
|
+
default: {
|
|
54
|
+
const { id, query } = args as RelatedContextArgs<'v1'>;
|
|
55
|
+
const params = new URLSearchParams(createSearchParameters(query || ''));
|
|
56
|
+
params.append('api-version', apiVersion);
|
|
57
|
+
return `/contexts/${id}/relations?${String(params)}`;
|
|
60
58
|
}
|
|
59
|
+
}
|
|
61
60
|
};
|
|
62
61
|
|
|
63
62
|
export default generateEndpoint;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ClientRequestInit, IHttpClient } from '@equinor/fusion-framework-module-http/client';
|
|
1
|
+
import type { ClientRequestInit, IHttpClient } from '@equinor/fusion-framework-module-http/client';
|
|
2
2
|
|
|
3
|
-
import { ApiVersion } from '..';
|
|
3
|
+
import type { ApiVersion } from '..';
|
|
4
4
|
|
|
5
5
|
import { generateEndpoint } from './generate-endpoint';
|
|
6
6
|
|
|
@@ -8,16 +8,16 @@ import type { RelatedContextArgs, ApiClientArguments } from './types';
|
|
|
8
8
|
|
|
9
9
|
/** Function for generating parameter for querying context service */
|
|
10
10
|
export const generateParameters = <
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
TResult,
|
|
12
|
+
TVersion extends string = keyof typeof ApiVersion,
|
|
13
|
+
TClient extends IHttpClient = IHttpClient,
|
|
14
14
|
>(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
version: TVersion,
|
|
16
|
+
args: RelatedContextArgs<TVersion>,
|
|
17
|
+
init?: ClientRequestInit<TClient, TResult>,
|
|
18
18
|
): ApiClientArguments<TClient, TResult> => {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const path = generateEndpoint(version, args);
|
|
20
|
+
return [path, init];
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export default generateParameters;
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import { IHttpClient, ClientRequestInit } from '@equinor/fusion-framework-module-http/client';
|
|
1
|
+
import type { IHttpClient, ClientRequestInit } from '@equinor/fusion-framework-module-http/client';
|
|
2
2
|
|
|
3
|
-
import { ApiVersion, ApiContextEntity, ClientMethod } from '..';
|
|
3
|
+
import { ApiVersion, type ApiContextEntity, type ClientMethod } from '..';
|
|
4
4
|
|
|
5
5
|
export { ApiClientArguments, ClientMethod } from '..';
|
|
6
6
|
|
|
7
7
|
export type ApiRelatedContextEntity<T extends ApiVersion> = ApiContextEntity<T> & {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
relationSource: string; // "ProjectMaster|OrgChart",
|
|
9
|
+
relationType: unknown;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export type RelatedContextOdataFilter = {
|
|
13
|
-
|
|
13
|
+
type?: string[];
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export type RelatedContextOdataParameters = {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
search?: string;
|
|
18
|
+
filter?: RelatedContextOdataFilter;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
type RelatedContextArgs_v1 = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
/** context id */
|
|
23
|
+
id: string;
|
|
24
|
+
query?: string | RelatedContextOdataParameters;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
type RelatedContextArgs_v2 = RelatedContextArgs_v1;
|
|
28
28
|
|
|
29
29
|
type RelatedContextArgTypes = {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
[ApiVersion.v1]: RelatedContextArgs_v1;
|
|
31
|
+
[ApiVersion.v2]: RelatedContextArgs_v2;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
export type RelatedContextArgs<T> = T extends keyof typeof ApiVersion
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
? RelatedContextArgTypes[(typeof ApiVersion)[T]]
|
|
36
|
+
: { id: string };
|
|
37
37
|
|
|
38
38
|
type RelatedContextResponseTypes = {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
[ApiVersion.v1]: Array<ApiRelatedContextEntity<ApiVersion.v1>>;
|
|
40
|
+
[ApiVersion.v2]: Array<ApiRelatedContextEntity<ApiVersion.v2>>;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
export type RelatedContextResponse<T> = T extends keyof typeof ApiVersion
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
? RelatedContextResponseTypes[(typeof ApiVersion)[T]]
|
|
45
|
+
: unknown;
|
|
46
46
|
|
|
47
47
|
export type RelatedContextFn<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
TVersion extends string = keyof typeof ApiVersion,
|
|
49
|
+
TMethod extends keyof ClientMethod<unknown> = keyof ClientMethod<unknown>,
|
|
50
|
+
TClient extends IHttpClient = IHttpClient,
|
|
51
|
+
TResult = RelatedContextResponse<TVersion>,
|
|
52
52
|
> = (
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
args: RelatedContextArgs<TVersion>,
|
|
54
|
+
init?: ClientRequestInit<TClient, TResult>,
|
|
55
55
|
) => RelatedContextResult<TVersion, TMethod, TResult>;
|
|
56
56
|
|
|
57
57
|
export type RelatedContextResult<
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
TVersion extends string = keyof typeof ApiVersion,
|
|
59
|
+
TMethod extends keyof ClientMethod<unknown> = keyof ClientMethod<unknown>,
|
|
60
|
+
TResult = RelatedContextResponse<TVersion>,
|
|
61
61
|
> = ClientMethod<TResult>[TMethod];
|
package/src/context/static.ts
CHANGED
package/src/errors.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export class UnsupportedApiVersion extends Error {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
constructor(
|
|
3
|
+
public readonly version: string | number,
|
|
4
|
+
cause?: unknown,
|
|
5
|
+
) {
|
|
6
|
+
super(`unsupported version ${version}`, { cause });
|
|
7
|
+
}
|
|
8
8
|
}
|