@equinor/fusion-framework-module-services 5.0.1 → 5.1.0-bookmark-preview-53d7010af49af3f3128a5ca800f7cfc796dc6089
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 +6 -0
- package/dist/esm/bookmarks/endpoints/user-bookmarks.get.js +52 -26
- package/dist/esm/bookmarks/endpoints/user-bookmarks.get.js.map +1 -1
- package/dist/esm/bookmarks/index.js +1 -0
- package/dist/esm/bookmarks/index.js.map +1 -1
- package/dist/esm/bookmarks/schemas.js +2 -2
- package/dist/esm/bookmarks/schemas.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/bookmarks/endpoints/bookmark.get.d.ts +28 -28
- package/dist/types/bookmarks/endpoints/bookmark.patch.d.ts +14 -14
- package/dist/types/bookmarks/endpoints/bookmark.post.d.ts +14 -14
- package/dist/types/bookmarks/endpoints/user-bookmarks.get.d.ts +231 -14
- package/dist/types/bookmarks/index.d.ts +1 -1
- package/dist/types/bookmarks/schemas.d.ts +31 -31
- package/package.json +3 -3
- package/src/bookmarks/endpoints/user-bookmarks.get.ts +56 -32
- package/src/bookmarks/index.ts +1 -1
- package/src/bookmarks/schemas.ts +2 -2
|
@@ -14,44 +14,65 @@ import { ApiVersion } from '../api-version';
|
|
|
14
14
|
import { ApiBookmarkSchema, ApiSourceSystem } from '../schemas';
|
|
15
15
|
|
|
16
16
|
/** API version which this operation uses. */
|
|
17
|
-
type AvailableVersions = ApiVersion.v1;
|
|
17
|
+
type AvailableVersions = ApiVersion.v1 | ApiVersion.v2;
|
|
18
18
|
|
|
19
19
|
/** Defines the allowed versions for this operation. (key of enum as string or enum value) */
|
|
20
20
|
type AllowedVersions = FilterAllowedApiVersions<AvailableVersions>;
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Schema transformer of the filter object to an OData filter string.
|
|
24
|
+
*
|
|
25
|
+
* @todo This function should be moved to a shared utility module.
|
|
26
|
+
*/
|
|
27
|
+
const transformOdataFilter = (filter: Record<string, unknown>) => {
|
|
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
|
+
};
|
|
48
|
+
|
|
49
|
+
const filterSchema_v1 = z
|
|
50
|
+
.object({
|
|
51
|
+
appKey: z.string().optional(),
|
|
52
|
+
contextId: z.string().optional(),
|
|
53
|
+
sourceSystem: ApiSourceSystem[ApiVersion.v1].partial().optional(),
|
|
54
|
+
})
|
|
55
|
+
.transform(transformOdataFilter);
|
|
56
|
+
|
|
57
|
+
const filterSchema_v2 = z
|
|
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
|
+
|
|
22
66
|
/** Schema for the input arguments to this operation. */
|
|
23
67
|
const ArgSchema = {
|
|
24
68
|
[ApiVersion.v1]: z
|
|
25
69
|
.object({
|
|
26
|
-
filter: z
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
contextId: z.string().optional(),
|
|
33
|
-
sourceSystem: ApiSourceSystem[ApiVersion.v1].partial().optional(),
|
|
34
|
-
})
|
|
35
|
-
.transform((x) => {
|
|
36
|
-
return Object.entries(x)
|
|
37
|
-
.map(([key, value]) => {
|
|
38
|
-
if (typeof value === 'string') {
|
|
39
|
-
return `${key} eq '${value}'`;
|
|
40
|
-
}
|
|
41
|
-
if (typeof value === 'object') {
|
|
42
|
-
return Object.entries(value)
|
|
43
|
-
.map(
|
|
44
|
-
([subKey, subValue]) =>
|
|
45
|
-
`${key}.${subKey} eq '${subValue}'`,
|
|
46
|
-
)
|
|
47
|
-
.join(' and ');
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
.filter((x) => !!x)
|
|
51
|
-
.join(' and ');
|
|
52
|
-
}),
|
|
53
|
-
)
|
|
54
|
-
.optional(),
|
|
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(),
|
|
55
76
|
})
|
|
56
77
|
.optional(),
|
|
57
78
|
};
|
|
@@ -59,6 +80,7 @@ const ArgSchema = {
|
|
|
59
80
|
/** Schema for the response from the API. */
|
|
60
81
|
const ApiResponseSchema = {
|
|
61
82
|
[ApiVersion.v1]: z.array(ApiBookmarkSchema[ApiVersion.v1]),
|
|
83
|
+
[ApiVersion.v2]: z.array(ApiBookmarkSchema[ApiVersion.v2]),
|
|
62
84
|
};
|
|
63
85
|
|
|
64
86
|
/** Defines the expected output from the api. */
|
|
@@ -85,7 +107,8 @@ const generateRequestParameters = <TResult, TVersion extends AvailableVersions>(
|
|
|
85
107
|
init?: ClientRequestInit<IHttpClient, TResult>,
|
|
86
108
|
): ClientRequestInit<IHttpClient, TResult> => {
|
|
87
109
|
switch (version) {
|
|
88
|
-
case ApiVersion.v1:
|
|
110
|
+
case ApiVersion.v1:
|
|
111
|
+
case ApiVersion.v2: {
|
|
89
112
|
const baseInit: FetchRequestInit<ApiResponse<ApiVersion.v1>, JsonRequest> = {
|
|
90
113
|
selector: schemaSelector(ApiResponseSchema[version]),
|
|
91
114
|
};
|
|
@@ -101,7 +124,8 @@ const generateApiPath = <TVersion extends AvailableVersions>(
|
|
|
101
124
|
args: z.infer<(typeof ArgSchema)[TVersion]>,
|
|
102
125
|
): string => {
|
|
103
126
|
switch (version) {
|
|
104
|
-
case ApiVersion.v1:
|
|
127
|
+
case ApiVersion.v1:
|
|
128
|
+
case ApiVersion.v2: {
|
|
105
129
|
const params = new URLSearchParams();
|
|
106
130
|
params.append('api-version', version);
|
|
107
131
|
args?.filter && params.append('$filter', args.filter);
|
package/src/bookmarks/index.ts
CHANGED
package/src/bookmarks/schemas.ts
CHANGED
|
@@ -17,7 +17,7 @@ export const ApiPersonSchema = {
|
|
|
17
17
|
accountType: z
|
|
18
18
|
.enum(['Employee', 'Consultant', 'External', 'Application', 'Local'])
|
|
19
19
|
.optional(),
|
|
20
|
-
accountClassification: z.enum(['Unclassified', 'Internal', 'External']).
|
|
20
|
+
accountClassification: z.enum(['Unclassified', 'Internal', 'External']).nullish(),
|
|
21
21
|
}),
|
|
22
22
|
};
|
|
23
23
|
|
|
@@ -55,7 +55,7 @@ export const ApiBookmarkSchema = {
|
|
|
55
55
|
updatedBy: ApiPersonSchema[ApiVersion.v1].optional(),
|
|
56
56
|
created: ApiDateSchema,
|
|
57
57
|
updated: ApiDateSchema.optional(),
|
|
58
|
-
sourceSystem: ApiSourceSystem[ApiVersion.v1].
|
|
58
|
+
sourceSystem: ApiSourceSystem[ApiVersion.v1].nullish(),
|
|
59
59
|
});
|
|
60
60
|
},
|
|
61
61
|
get [ApiVersion.v2]() {
|