@equinor/fusion-framework-module-bookmark 0.1.4 → 0.2.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.
@@ -2,7 +2,7 @@ import { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-mo
2
2
  import { BookmarkClient } from './client/bookmarkClient';
3
3
  import { BookmarkModuleConfig } from './configurator';
4
4
  import { Observable } from 'rxjs';
5
- import { Bookmark } from './types';
5
+ import { Bookmark, PatchBookmark, UpdateBookmarkOptions } from './types';
6
6
  export interface IBookmarkModuleProvider {
7
7
  readonly config: BookmarkModuleConfig;
8
8
  readonly currentBookmark$: Observable<Bookmark<any> | undefined>;
@@ -13,9 +13,12 @@ export interface IBookmarkModuleProvider {
13
13
  getAllBookmarks(): Observable<Array<Bookmark>>;
14
14
  getAllBookmarksAsync(): Promise<Array<Bookmark>>;
15
15
  updateBookmark<T>(bookmark: Bookmark<T>): Observable<Bookmark<T>>;
16
- updateBookmarkAsync<T>(bookmark: Bookmark<T>): Promise<Bookmark<T>>;
16
+ updateBookmarkAsync<T>(bookmark: PatchBookmark<T>, options?: UpdateBookmarkOptions): Promise<Bookmark<T> | undefined>;
17
17
  deleteBookmarkById(bookmarkId: string): Observable<string>;
18
18
  deleteBookmarkByIdAsync(bookmarkId: string): Promise<string>;
19
+ addBookmarkFavoriteAsync(bookmarkId: string): Promise<void>;
20
+ removeBookmarkFavoriteAsync(bookmarkId: string): Promise<void>;
21
+ verifyBookmarkFavoriteAsync(bookmarkId: string): Promise<boolean>;
19
22
  setCurrentBookmark<TData>(idOrItem?: string | Bookmark<TData>): void;
20
23
  createBookmark<T>(args: {
21
24
  name: string;
@@ -40,10 +43,13 @@ export declare class BookmarkModuleProvider implements IBookmarkModuleProvider {
40
43
  setCurrentBookmark<TData>(idOrItem?: string | Bookmark<TData>): Promise<void>;
41
44
  getAllBookmarks(): Observable<Bookmark<unknown>[]>;
42
45
  getAllBookmarksAsync(): Promise<Bookmark<unknown>[]>;
43
- updateBookmark<T>(bookmark: Bookmark<T>): Observable<Bookmark<T>>;
44
- updateBookmarkAsync<T>(bookmark: Bookmark<T>): Promise<Bookmark<T>>;
46
+ updateBookmark<T>(bookmark: PatchBookmark<T>): Observable<Bookmark<T>>;
47
+ updateBookmarkAsync<T>(bookmark: PatchBookmark<T>, options?: UpdateBookmarkOptions): Promise<Bookmark<T> | undefined>;
45
48
  deleteBookmarkById(bookmarkId: string): Observable<string>;
46
49
  deleteBookmarkByIdAsync(bookmarkId: string): Promise<string>;
50
+ addBookmarkFavoriteAsync(bookmarkId: string): Promise<void>;
51
+ removeBookmarkFavoriteAsync(bookmarkId: string): Promise<void>;
52
+ verifyBookmarkFavoriteAsync(bookmarkId: string): Promise<boolean>;
47
53
  addStateCreator<T>(cb: CreateBookmarkFn<T>, key?: keyof T): VoidFunction;
48
54
  createBookmark<T>(args: {
49
55
  name: string;
@@ -1,5 +1,5 @@
1
1
  import { ActionInstanceMap, ActionTypes } from '@equinor/fusion-observable';
2
- import { Bookmark, CreateBookmark } from '../types';
2
+ import { Bookmark, CreateBookmark, PatchBookmark } from '../types';
3
3
  export declare const actions: {
4
4
  getAll: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[isValid: boolean], boolean, "getAll::request", never, never> & {
5
5
  success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[bookmarks: Bookmark<unknown>[]], Bookmark<unknown>[], "getAll::success", never, never>;
@@ -8,7 +8,7 @@ export declare const actions: {
8
8
  delete: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[id: string], string, "delete::request", never, never> & {
9
9
  success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[id: string], string, "delete::success", never, never>;
10
10
  };
11
- update: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[bookmark: Bookmark<unknown>], Bookmark<unknown>, "update::request", never, never> & {
11
+ update: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[bookmark: PatchBookmark<unknown>], PatchBookmark<unknown>, "update::request", never, never> & {
12
12
  success: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[bookmark: Bookmark<unknown>], Bookmark<unknown>, "update::success", never, never>;
13
13
  };
14
14
  create: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[bookmark: CreateBookmark<unknown>], CreateBookmark<unknown>, "create::request", never, never> & {
@@ -3,7 +3,7 @@ import { IHttpClient } from '@equinor/fusion-framework-module-http';
3
3
  import { BookmarksApiClient } from '@equinor/fusion-framework-module-services/bookmarks';
4
4
  import { type QueryCtorOptions } from '@equinor/fusion-query';
5
5
  import { Observable } from 'rxjs';
6
- import { Bookmark, CreateBookmark, GetAllBookmarksParameters, GetBookmarkParameters, SourceSystem } from '../types';
6
+ import { Bookmark, CreateBookmark, GetAllBookmarksParameters, GetBookmarkParameters, PatchBookmark, SourceSystem } from '../types';
7
7
  export type BookmarkClientConfig = {
8
8
  client: BookmarksApiClient<'fetch', IHttpClient, Bookmark<unknown>>;
9
9
  queryClientConfig: {
@@ -30,10 +30,13 @@ export declare class BookmarkClient {
30
30
  getBookmarkById<T>(bookmarkId: string): Promise<Bookmark<T>>;
31
31
  createBookmark(bookmark: CreateBookmark<unknown>): Observable<Bookmark<unknown>>;
32
32
  createBookmarkAsync(bookmark: CreateBookmark<unknown>): Promise<Bookmark<unknown>>;
33
- updateBookmark<T>(bookmark: Bookmark<T>): Observable<Bookmark<T>>;
34
- updateBookmarkAsync<T>(bookmark: Bookmark<T>): Promise<Bookmark<T>>;
33
+ updateBookmark<T>(bookmark: PatchBookmark<T>): Observable<Bookmark<T>>;
34
+ updateBookmarkAsync<T>(bookmark: PatchBookmark<T>): Promise<Bookmark<T>>;
35
35
  deleteBookmarkById(bookmarkId: string): Observable<string>;
36
36
  deleteBookmarkByIdAsync(bookmarkId: string): Promise<string>;
37
+ addBookmarkFavoriteAsync(bookmarkId: string): Promise<void>;
38
+ removeBookmarkFavoriteAsync(bookmarkId: string): Promise<void>;
39
+ verifyBookmarkFavoriteAsync(bookmarkId: string): Promise<boolean>;
37
40
  dispose(): void;
38
41
  }
39
42
  declare module '@equinor/fusion-framework-module-event' {
@@ -1,4 +1,8 @@
1
1
  import { QueryFn, QueryCtorOptions } from '@equinor/fusion-query';
2
+ export interface PatchBookmark<TData = unknown> extends Partial<Bookmark<TData>> {
3
+ id: string;
4
+ appKey: string;
5
+ }
2
6
  export interface Bookmark<TData = unknown> {
3
7
  id: string;
4
8
  name: string;
@@ -51,4 +55,7 @@ export interface BookmarkQueryClient {
51
55
  getAllBookmarks: QueryFn<Array<Bookmark<unknown>>, GetAllBookmarksParameters> | QueryCtorOptions<Array<Bookmark<unknown>>, GetAllBookmarksParameters>;
52
56
  getBookmarkById: QueryFn<Bookmark<unknown>, GetBookmarkParameters> | QueryCtorOptions<Bookmark<unknown>, GetBookmarkParameters>;
53
57
  }
58
+ export type UpdateBookmarkOptions = {
59
+ updatePayload: boolean;
60
+ };
54
61
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-module-bookmark",
3
- "version": "0.1.4",
3
+ "version": "0.2.1",
4
4
  "description": "",
5
5
  "main": "./dist/esm/index.js",
6
6
  "exports": {
@@ -37,12 +37,12 @@
37
37
  "devDependencies": {
38
38
  "@equinor/fusion-framework-module": "^2.0.0",
39
39
  "@equinor/fusion-framework-module-event": "^2.0.0",
40
- "@equinor/fusion-framework-module-services": "^2.3.0",
40
+ "@equinor/fusion-framework-module-services": "^2.3.1",
41
41
  "rxjs": "^7.5.7"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@equinor/fusion-framework-module": ">=1.2.5",
45
45
  "rxjs": "^7.5.7"
46
46
  },
47
- "gitHead": "2cec998dee5e0781c2cc2b327e2e119d12cd0046"
47
+ "gitHead": "1dd3688d5ac207281d512fcb88fdb9409ad62748"
48
48
  }
@@ -10,7 +10,7 @@ import { BookmarkClient } from './client/bookmarkClient';
10
10
 
11
11
  import { BookmarkModuleConfig } from './configurator';
12
12
  import { Observable, Subscription } from 'rxjs';
13
- import { Bookmark, CreateBookmark } from './types';
13
+ import { Bookmark, CreateBookmark, PatchBookmark, UpdateBookmarkOptions } from './types';
14
14
 
15
15
  export interface IBookmarkModuleProvider {
16
16
  /**
@@ -83,9 +83,13 @@ export interface IBookmarkModuleProvider {
83
83
  * @template T - Payload Type
84
84
  * @param {string} bookmarkId
85
85
  * @param {Bookmark<T>} bookmark
86
+ * @param {UpdateBookmarkOptions} options - optional options that allow for configuration of bookmark payload update.
86
87
  * @return {Promise<Bookmark<T>>} - Promise of a Bookmark
87
88
  */
88
- updateBookmarkAsync<T>(bookmark: Bookmark<T>): Promise<Bookmark<T>>;
89
+ updateBookmarkAsync<T>(
90
+ bookmark: PatchBookmark<T>,
91
+ options?: UpdateBookmarkOptions
92
+ ): Promise<Bookmark<T> | undefined>;
89
93
 
90
94
  /**
91
95
  * Function for deleting a bookmark, when successful this will update the bookmark list.
@@ -101,6 +105,27 @@ export interface IBookmarkModuleProvider {
101
105
  */
102
106
  deleteBookmarkByIdAsync(bookmarkId: string): Promise<string>;
103
107
 
108
+ /**
109
+ * Function for adding external bookmark to user's bookmarks.
110
+ * @param {string} bookmarkId
111
+ * @return {Promise<string>} void
112
+ */
113
+ addBookmarkFavoriteAsync(bookmarkId: string): Promise<void>;
114
+
115
+ /**
116
+ * Function for removing external bookmark to user's bookmarks.
117
+ * @param {string} bookmarkId
118
+ * @return {Promise<void>} - void
119
+ */
120
+ removeBookmarkFavoriteAsync(bookmarkId: string): Promise<void>;
121
+
122
+ /**
123
+ * Function for verifying that a bookmark belongs to the current user.
124
+ * @param {string} bookmarkId
125
+ * @return {Promise<string>} - void
126
+ */
127
+ verifyBookmarkFavoriteAsync(bookmarkId: string): Promise<boolean>;
128
+
104
129
  /**
105
130
  * Function for setting the current bookmark, when successful this will update the bookmark list.
106
131
  * @template TData - Bookmark payload type.
@@ -191,11 +216,21 @@ export class BookmarkModuleProvider implements IBookmarkModuleProvider {
191
216
  return this._bookmarkClient.getAllBookmarksAsync();
192
217
  }
193
218
 
194
- public updateBookmark<T>(bookmark: Bookmark<T>): Observable<Bookmark<T>> {
219
+ public updateBookmark<T>(bookmark: PatchBookmark<T>): Observable<Bookmark<T>> {
195
220
  return this._bookmarkClient.updateBookmark<T>(bookmark);
196
221
  }
197
222
 
198
- public async updateBookmarkAsync<T>(bookmark: Bookmark<T>): Promise<Bookmark<T>> {
223
+ public async updateBookmarkAsync<T>(
224
+ bookmark: PatchBookmark<T>,
225
+ options?: UpdateBookmarkOptions
226
+ ): Promise<Bookmark<T> | undefined> {
227
+ if (this.#getAppKey() !== bookmark.appKey) {
228
+ return;
229
+ }
230
+
231
+ if (options?.updatePayload) {
232
+ bookmark.payload = (await this.#createPayload()) as T;
233
+ }
199
234
  return this._bookmarkClient.updateBookmarkAsync<T>(bookmark);
200
235
  }
201
236
 
@@ -207,6 +242,18 @@ export class BookmarkModuleProvider implements IBookmarkModuleProvider {
207
242
  return this._bookmarkClient.deleteBookmarkByIdAsync(bookmarkId);
208
243
  }
209
244
 
245
+ public async addBookmarkFavoriteAsync(bookmarkId: string): Promise<void> {
246
+ await this._bookmarkClient.addBookmarkFavoriteAsync(bookmarkId);
247
+ }
248
+
249
+ public async removeBookmarkFavoriteAsync(bookmarkId: string): Promise<void> {
250
+ await this._bookmarkClient.removeBookmarkFavoriteAsync(bookmarkId);
251
+ }
252
+
253
+ public async verifyBookmarkFavoriteAsync(bookmarkId: string): Promise<boolean> {
254
+ return await this._bookmarkClient.verifyBookmarkFavoriteAsync(bookmarkId);
255
+ }
256
+
210
257
  public addStateCreator<T>(cb: CreateBookmarkFn<T>, key?: keyof T): VoidFunction {
211
258
  const bookmarkCreatorKey = key ? key : '#creator';
212
259
 
@@ -232,12 +279,7 @@ export class BookmarkModuleProvider implements IBookmarkModuleProvider {
232
279
  const payload = await this.#createPayload();
233
280
 
234
281
  const contextId = this.config.getContextId && this.config.getContextId();
235
- const appKey =
236
- this.config.getCurrentAppIdentification && this.config.getCurrentAppIdentification();
237
-
238
- if (!appKey)
239
- throw new Error(`There is noe current application selected, can't create bookmark.`);
240
-
282
+ const appKey = this.#getAppKey();
241
283
  const bookmark: CreateBookmark<unknown> = {
242
284
  ...args,
243
285
  appKey,
@@ -268,6 +310,16 @@ export class BookmarkModuleProvider implements IBookmarkModuleProvider {
268
310
  }, Promise.resolve({}));
269
311
  }
270
312
 
313
+ #getAppKey() {
314
+ const appKey =
315
+ this.config.getCurrentAppIdentification && this.config.getCurrentAppIdentification();
316
+
317
+ if (!appKey)
318
+ throw new Error(`There is noe current application selected, can't create bookmark.`);
319
+
320
+ return appKey;
321
+ }
322
+
271
323
  public dispose() {
272
324
  this.#subscriptions.unsubscribe();
273
325
  this._bookmarkClient.dispose();
@@ -1,6 +1,6 @@
1
1
  import { createAsyncAction, ActionInstanceMap, ActionTypes } from '@equinor/fusion-observable';
2
2
 
3
- import { Bookmark, CreateBookmark } from '../types';
3
+ import { Bookmark, CreateBookmark, PatchBookmark } from '../types';
4
4
 
5
5
  export const actions = {
6
6
  getAll: createAsyncAction(
@@ -16,7 +16,7 @@ export const actions = {
16
16
  ),
17
17
  update: createAsyncAction(
18
18
  'update',
19
- (bookmark: Bookmark) => ({ payload: bookmark }),
19
+ (bookmark: PatchBookmark) => ({ payload: bookmark }),
20
20
  (bookmark: Bookmark) => ({ payload: bookmark })
21
21
  ),
22
22
  create: createAsyncAction(
@@ -17,6 +17,7 @@ import {
17
17
  CreateBookmark,
18
18
  GetAllBookmarksParameters,
19
19
  GetBookmarkParameters,
20
+ PatchBookmark,
20
21
  SourceSystem,
21
22
  } from '../types';
22
23
  import { ActionBuilder, actions } from './bookmarkActions';
@@ -192,7 +193,7 @@ export class BookmarkClient {
192
193
  return lastValueFrom(this.createBookmark(bookmark));
193
194
  }
194
195
 
195
- public updateBookmark<T>(bookmark: Bookmark<T>): Observable<Bookmark<T>> {
196
+ public updateBookmark<T>(bookmark: PatchBookmark<T>): Observable<Bookmark<T>> {
196
197
  return new Observable((subscriber) => {
197
198
  this.#state.dispatch.update(bookmark);
198
199
  subscriber.add(
@@ -205,7 +206,7 @@ export class BookmarkClient {
205
206
  });
206
207
  }
207
208
 
208
- public async updateBookmarkAsync<T>(bookmark: Bookmark<T>): Promise<Bookmark<T>> {
209
+ public async updateBookmarkAsync<T>(bookmark: PatchBookmark<T>): Promise<Bookmark<T>> {
209
210
  return lastValueFrom(this.updateBookmark(bookmark));
210
211
  }
211
212
 
@@ -226,6 +227,20 @@ export class BookmarkClient {
226
227
  return lastValueFrom(this.deleteBookmarkById(bookmarkId));
227
228
  }
228
229
 
230
+ public async addBookmarkFavoriteAsync(bookmarkId: string): Promise<void> {
231
+ this.#bookmarkAPiClient.addFavorite('v1', { bookmarkId });
232
+ }
233
+
234
+ public async removeBookmarkFavoriteAsync(bookmarkId: string): Promise<void> {
235
+ this.#bookmarkAPiClient.removeFavorite('v1', { bookmarkId });
236
+ }
237
+
238
+ public async verifyBookmarkFavoriteAsync(bookmarkId: string): Promise<boolean> {
239
+ const response = await this.#bookmarkAPiClient.verifyFavorite('v1', { bookmarkId });
240
+ if (response.ok) return true;
241
+ return false;
242
+ }
243
+
229
244
  dispose(): void {
230
245
  this.#subscriptions.unsubscribe();
231
246
  }
package/src/types.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import { QueryFn, QueryCtorOptions } from '@equinor/fusion-query';
2
2
 
3
+ export interface PatchBookmark<TData = unknown> extends Partial<Bookmark<TData>> {
4
+ id: string;
5
+ appKey: string;
6
+ }
3
7
  export interface Bookmark<TData = unknown> {
4
8
  id: string;
5
9
  name: string;
@@ -63,3 +67,7 @@ export interface BookmarkQueryClient {
63
67
  | QueryFn<Bookmark<unknown>, GetBookmarkParameters>
64
68
  | QueryCtorOptions<Bookmark<unknown>, GetBookmarkParameters>;
65
69
  }
70
+
71
+ export type UpdateBookmarkOptions = {
72
+ updatePayload: boolean;
73
+ };