@equinor/fusion-framework-module-services 5.0.0 → 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.
Files changed (30) hide show
  1. package/CHANGELOG.md +200 -184
  2. package/dist/esm/bookmarks/endpoints/user-bookmark-favourite.head.js +1 -2
  3. package/dist/esm/bookmarks/endpoints/user-bookmark-favourite.head.js.map +1 -1
  4. package/dist/esm/bookmarks/endpoints/user-bookmarks.get.js +52 -26
  5. package/dist/esm/bookmarks/endpoints/user-bookmarks.get.js.map +1 -1
  6. package/dist/esm/bookmarks/index.js +1 -0
  7. package/dist/esm/bookmarks/index.js.map +1 -1
  8. package/dist/esm/bookmarks/schemas.js +2 -2
  9. package/dist/esm/bookmarks/schemas.js.map +1 -1
  10. package/dist/esm/bookmarks/selectors.js +8 -12
  11. package/dist/esm/bookmarks/selectors.js.map +1 -1
  12. package/dist/esm/provider.js +3 -1
  13. package/dist/esm/provider.js.map +1 -1
  14. package/dist/esm/version.js +1 -1
  15. package/dist/tsconfig.tsbuildinfo +1 -1
  16. package/dist/types/bookmarks/endpoints/bookmark.get.d.ts +28 -28
  17. package/dist/types/bookmarks/endpoints/bookmark.patch.d.ts +14 -14
  18. package/dist/types/bookmarks/endpoints/bookmark.post.d.ts +14 -14
  19. package/dist/types/bookmarks/endpoints/user-bookmarks.get.d.ts +231 -14
  20. package/dist/types/bookmarks/index.d.ts +1 -1
  21. package/dist/types/bookmarks/schemas.d.ts +31 -31
  22. package/dist/types/version.d.ts +1 -1
  23. package/package.json +2 -2
  24. package/src/bookmarks/endpoints/user-bookmark-favourite.head.ts +1 -2
  25. package/src/bookmarks/endpoints/user-bookmarks.get.ts +56 -32
  26. package/src/bookmarks/index.ts +1 -1
  27. package/src/bookmarks/schemas.ts +2 -2
  28. package/src/bookmarks/selectors.ts +8 -11
  29. package/src/provider.ts +3 -1
  30. package/src/version.ts +1 -1
@@ -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
- .string()
28
- .or(
29
- z
30
- .object({
31
- appKey: z.string().optional(),
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);
@@ -1,4 +1,4 @@
1
1
  export { BookmarksApiClient, default } from './client';
2
2
  export { ApiVersion } from './api-version';
3
- export type * from './schemas';
3
+ export * from './schemas';
4
4
  export type * from './types';
@@ -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']).optional(),
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].optional(),
58
+ sourceSystem: ApiSourceSystem[ApiVersion.v1].nullish(),
59
59
  });
60
60
  },
61
61
  get [ApiVersion.v2]() {
@@ -1,4 +1,4 @@
1
- import { HttpJsonResponseError } from '@equinor/fusion-framework-module-http';
1
+ import { HttpJsonResponseError, HttpResponseError } from '@equinor/fusion-framework-module-http';
2
2
  import { type ResponseSelector } from '@equinor/fusion-framework-module-http/selectors';
3
3
 
4
4
  /**
@@ -35,15 +35,12 @@ export const statusSelector: ResponseSelector<boolean> = async (res) => {
35
35
  * @returns `true` if the response is successful, `false` if the response has a 404 status code, otherwise throws an `HttpJsonResponseError`.
36
36
  * @throws {HttpJsonResponseError} If the response is not successful and does not have a 404 status code, with the error message, response, and any additional data or cause.
37
37
  */
38
- export const headSelector: ResponseSelector<boolean> = (res) => {
39
- try {
40
- return statusSelector(res);
41
- } catch (error) {
42
- if (error instanceof HttpJsonResponseError) {
43
- if (error.response.status === 404) {
44
- return Promise.resolve(false);
45
- }
46
- }
47
- throw error;
38
+ export const headSelector: ResponseSelector<boolean> = async (res) => {
39
+ if (res.ok) {
40
+ return true;
41
+ }
42
+ if (res.status === 404) {
43
+ return false;
48
44
  }
45
+ throw new HttpResponseError(`Failed to execute request. Status code: ${res.status}`, res);
49
46
  };
package/src/provider.ts CHANGED
@@ -96,7 +96,9 @@ export class ApiProvider<TClient extends IHttpClient = IHttpClient>
96
96
  method: TMethod,
97
97
  ): Promise<BookmarksApiClient<TMethod, TClient>> {
98
98
  const httpClient = await this._createClientFn('bookmarks');
99
- httpClient.responseHandler.add('validate_api_request', validateResponse);
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);
100
102
  return new BookmarksApiClient(httpClient, method);
101
103
  }
102
104
 
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '5.0.0';
2
+ export const version = '5.0.1';