@equinor/fusion-framework-module-bookmark 3.0.6 → 4.0.0

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 (47) hide show
  1. package/CHANGELOG.md +30 -18
  2. package/README.md +156 -255
  3. package/dist/esm/BookmarkClient.js +10 -0
  4. package/dist/esm/BookmarkClient.js.map +1 -1
  5. package/dist/esm/BookmarkConfigurator.js +8 -1
  6. package/dist/esm/BookmarkConfigurator.js.map +1 -1
  7. package/dist/esm/BookmarkProvider.error.js +17 -1
  8. package/dist/esm/BookmarkProvider.error.js.map +1 -1
  9. package/dist/esm/BookmarkProvider.selectors.js +14 -7
  10. package/dist/esm/BookmarkProvider.selectors.js.map +1 -1
  11. package/dist/esm/BookmarkProvider.store.js +6 -5
  12. package/dist/esm/BookmarkProvider.store.js.map +1 -1
  13. package/dist/esm/bookmark-config.schema.js +13 -0
  14. package/dist/esm/bookmark-config.schema.js.map +1 -1
  15. package/dist/esm/bookmark-module.js +16 -0
  16. package/dist/esm/bookmark-module.js.map +1 -1
  17. package/dist/esm/bookmark.schemas.js +22 -0
  18. package/dist/esm/bookmark.schemas.js.map +1 -1
  19. package/dist/esm/enable-bookmark.js +21 -3
  20. package/dist/esm/enable-bookmark.js.map +1 -1
  21. package/dist/esm/version.js +1 -1
  22. package/dist/tsconfig.tsbuildinfo +1 -1
  23. package/dist/types/BookmarkClient.d.ts +10 -0
  24. package/dist/types/BookmarkConfigurator.d.ts +8 -1
  25. package/dist/types/BookmarkProvider.actions.d.ts +1 -0
  26. package/dist/types/BookmarkProvider.error.d.ts +18 -1
  27. package/dist/types/BookmarkProvider.interface.d.ts +37 -0
  28. package/dist/types/BookmarkProvider.selectors.d.ts +14 -7
  29. package/dist/types/BookmarkProvider.store.d.ts +16 -7
  30. package/dist/types/bookmark-config.schema.d.ts +13 -0
  31. package/dist/types/bookmark-module.d.ts +23 -0
  32. package/dist/types/bookmark.schemas.d.ts +22 -0
  33. package/dist/types/enable-bookmark.d.ts +21 -3
  34. package/dist/types/version.d.ts +1 -1
  35. package/package.json +12 -13
  36. package/src/BookmarkClient.ts +10 -0
  37. package/src/BookmarkConfigurator.ts +8 -1
  38. package/src/BookmarkProvider.actions.ts +1 -0
  39. package/src/BookmarkProvider.error.ts +15 -0
  40. package/src/BookmarkProvider.interface.ts +37 -0
  41. package/src/BookmarkProvider.selectors.ts +14 -7
  42. package/src/BookmarkProvider.store.ts +16 -7
  43. package/src/bookmark-config.schema.ts +13 -0
  44. package/src/bookmark-module.ts +23 -0
  45. package/src/bookmark.schemas.ts +22 -0
  46. package/src/enable-bookmark.ts +21 -3
  47. package/src/version.ts +1 -1
@@ -29,14 +29,24 @@ export declare class BookmarkClient implements IBookmarkClient {
29
29
  constructor(api: BookmarksApiClient<'json$'>, options?: {
30
30
  expire?: number;
31
31
  });
32
+ /** @inheritdoc */
32
33
  getAllBookmarks(filter?: BookmarksFilter): ObservableInput<Bookmark[]>;
34
+ /** @inheritdoc */
33
35
  getBookmarkById(bookmarkId: string): ObservableInput<BookmarkWithoutData>;
36
+ /** @inheritdoc */
34
37
  getBookmarkData<T extends BookmarkData>(bookmarkId: string): ObservableInput<T>;
38
+ /** @inheritdoc */
35
39
  setBookmarkData<T extends BookmarkData | null>(bookmarkId: string, data: T): ObservableInput<T>;
40
+ /** @inheritdoc */
36
41
  createBookmark<T extends BookmarkData>(newBookmark: BookmarkNew<T>): ObservableInput<Bookmark<T>>;
42
+ /** @inheritdoc */
37
43
  updateBookmark<T extends BookmarkData>(bookmarkId: string, updates: BookmarkUpdate<T>): ObservableInput<Bookmark<T>>;
44
+ /** @inheritdoc */
38
45
  deleteBookmark(bookmarkId: string): ObservableInput<boolean>;
46
+ /** @inheritdoc */
39
47
  addBookmarkToFavorites(bookmarkId: string): ObservableInput<boolean>;
48
+ /** @inheritdoc */
40
49
  removeBookmarkFromFavorites(bookmarkId: string): ObservableInput<boolean>;
50
+ /** @inheritdoc */
41
51
  isBookmarkFavorite(bookmarkId: string): ObservableInput<boolean>;
42
52
  }
@@ -5,7 +5,14 @@ import type { BookmarkModule } from './bookmark-module';
5
5
  import type { BookmarkModuleConfig } from './types';
6
6
  /**
7
7
  * Configurator for the bookmark module.
8
- * This class provides a set of methods for configuring the bookmark module.
8
+ *
9
+ * Provides a builder-style API for setting the source system, bookmark client,
10
+ * context/application resolvers, filters, and parent provider before the module
11
+ * is initialised. Extends {@link BaseConfigBuilder} and produces a validated
12
+ * {@link BookmarkModuleConfig} at build time.
13
+ *
14
+ * In most cases you interact with this class through the callback provided to
15
+ * {@link enableBookmark} rather than instantiating it directly.
9
16
  */
10
17
  export declare class BookmarkModuleConfigurator extends BaseConfigBuilder<BookmarkModuleConfig> {
11
18
  #private;
@@ -83,5 +83,6 @@ export declare const bookmarkActions: {
83
83
  failure: import("@equinor/fusion-observable").ActionCreatorWithPreparedPayload<[error: BookmarkFlowError, meta: BookmarkActionMeta], BookmarkFlowError, "remove_favourite_bookmark::failure", never, BookmarkActionMeta>;
84
84
  };
85
85
  };
86
+ /** Union type of all action objects produced by {@link bookmarkActions}. */
86
87
  export type BookmarkActions = ActionTypes<typeof bookmarkActions>;
87
88
  export {};
@@ -1,9 +1,26 @@
1
1
  import type { ActionWithSuffix } from '@equinor/fusion-observable';
2
2
  import type { BookmarkActions } from './BookmarkProvider.actions';
3
+ /**
4
+ * Error thrown inside bookmark store flows (side-effect pipelines) when an
5
+ * API call or observable chain fails.
6
+ *
7
+ * Carries a reference to the originating request action so callers can
8
+ * correlate errors back to specific operations.
9
+ */
3
10
  export declare class BookmarkFlowError extends Error {
11
+ /** The request action that triggered the failed flow. */
4
12
  readonly action: ActionWithSuffix<BookmarkActions, 'request'>;
5
- constructor(message: string, action: ActionWithSuffix<BookmarkActions, 'request'>, options?: ErrorOptions);
13
+ constructor(message: string,
14
+ /** The request action that triggered the failed flow. */
15
+ action: ActionWithSuffix<BookmarkActions, 'request'>, options?: ErrorOptions);
6
16
  }
17
+ /**
18
+ * General-purpose error thrown by {@link BookmarkProvider} methods when a
19
+ * high-level operation (create, update, delete, set current, etc.) fails.
20
+ *
21
+ * Distinct from {@link BookmarkFlowError}, which is scoped to internal
22
+ * store flow pipelines.
23
+ */
7
24
  export declare class BookmarkProviderError extends Error {
8
25
  constructor(message: string, options?: ErrorOptions);
9
26
  }
@@ -3,10 +3,37 @@ import type { Bookmark, BookmarkData, BookmarkWithoutData } from './types';
3
3
  import type { BookmarkNew, BookmarkUpdate } from './BookmarkClient.interface';
4
4
  import type { BookmarkProviderEventMap } from './BookmarkProvider.events';
5
5
  import type { BookmarkState } from './BookmarkProvider.store';
6
+ /**
7
+ * Arguments for creating a bookmark via {@link IBookmarkProvider.createBookmark}.
8
+ *
9
+ * Omits fields that the provider resolves automatically (`appKey`, `contextId`, `sourceSystem`),
10
+ * but allows the caller to override `appKey` if needed.
11
+ *
12
+ * @template T - The type of payload data stored in the bookmark.
13
+ */
6
14
  export type BookmarkCreateArgs<T extends BookmarkData = any> = Omit<BookmarkNew<T>, 'appKey' | 'contextId' | 'sourceSystem'> & Partial<Pick<BookmarkNew<T>, 'appKey'>>;
15
+ /**
16
+ * Options that control how {@link IBookmarkProvider.updateBookmark} processes an update.
17
+ *
18
+ * @property excludePayloadGeneration - When `true`, skip running registered payload generators
19
+ * and send the update payload as-is. Useful when the caller has already computed the full payload.
20
+ */
7
21
  export type BookmarkUpdateOptions = {
8
22
  excludePayloadGeneration?: boolean;
9
23
  };
24
+ /**
25
+ * Callback registered with {@link IBookmarkProvider.addPayloadGenerator} that participates
26
+ * in building or transforming bookmark payload data during create and update operations.
27
+ *
28
+ * The `payload` argument is an Immer draft — mutate it in place rather than returning a new
29
+ * object. If the generator returns a value it will be used, but this is discouraged.
30
+ * Return `null` to signal that the bookmark payload should be cleared.
31
+ *
32
+ * @template TData - Shape of the bookmark payload.
33
+ * @param payload - The accumulated payload draft from previous generators (mutable).
34
+ * @param initial - The original payload before any generators ran (read-only reference).
35
+ * @returns A partial payload, `void` (when mutating the draft), or `null` to clear.
36
+ */
10
37
  export type BookmarkPayloadGenerator<TData extends BookmarkData = any> = (payload?: Partial<TData> | null, initial?: Partial<TData> | null) => Promise<Partial<TData> | void> | Partial<TData> | void;
11
38
  /**
12
39
  * Interface representing a Bookmark Provider.
@@ -95,6 +122,16 @@ export interface IBookmarkProvider {
95
122
  * @returns {ObservableInput<boolean>} An observable input indicating whether the bookmark is in the favorites.
96
123
  */
97
124
  isBookmarkInFavorites(bookmarkId: string): ObservableInput<boolean>;
125
+ /**
126
+ * Registers a payload generator that runs during bookmark create and update operations.
127
+ *
128
+ * Multiple generators can be registered and they execute sequentially, each receiving
129
+ * the accumulated payload from previous generators.
130
+ *
131
+ * @template TData - Shape of the bookmark payload.
132
+ * @param generator - The generator callback to register.
133
+ * @returns A disposal function that unregisters the generator when called.
134
+ */
98
135
  addPayloadGenerator<TData extends BookmarkData>(generator: BookmarkPayloadGenerator<TData>): VoidFunction;
99
136
  /**
100
137
  * Registers an event listener for bookmark provider events.
@@ -2,20 +2,27 @@ import type { BookmarkFlowError } from './BookmarkProvider.error';
2
2
  import type { BookmarkState } from './BookmarkProvider.store';
3
3
  import type { Bookmark, BookmarkData } from './types';
4
4
  /**
5
- * Selects all bookmarks from the application state.
5
+ * Selects all bookmarks from the store state as an array.
6
+ *
7
+ * @param state - The current bookmark store state.
8
+ * @returns An array of all bookmarks.
6
9
  */
7
10
  export declare const bookmarksSelector: (state: BookmarkState) => Bookmark[];
8
11
  /**
9
- * Retrieves a bookmark from the state by its ID.
12
+ * Retrieves a single bookmark from the store state by its ID.
13
+ *
14
+ * @template T - The bookmark payload data shape.
15
+ * @param state - The current bookmark store state.
16
+ * @param id - The bookmark identifier to look up.
17
+ * @returns The matching bookmark, or `undefined` if not found.
10
18
  */
11
19
  export declare const bookmarkSelector: <T extends BookmarkData>(state: BookmarkState, id: string) => Bookmark<T> | undefined;
12
20
  /**
13
- * Selects the active bookmark from the bookmark state.
14
- *
15
- * if there is an active bookmark, the function returns the bookmark data.
21
+ * Selects the currently active bookmark from the store state.
16
22
  *
17
- * if there is no active bookmark, the function returns null.
18
- * if the active bookmark was never set, the function returns undefined.
23
+ * @template T - The bookmark payload data shape.
24
+ * @param state - The current bookmark store state.
25
+ * @returns The active bookmark, `null` if explicitly cleared, or `undefined` if never set.
19
26
  */
20
27
  export declare const activeBookmarkSelector: <T extends BookmarkData>(state: BookmarkState) => Bookmark<T> | null | undefined;
21
28
  /**
@@ -4,7 +4,12 @@ import type { BookmarkFlowError } from './BookmarkProvider.error';
4
4
  import type { IBookmarkClient } from './BookmarkClient.interface';
5
5
  import type { Bookmark, BookmarkWithoutData } from './types';
6
6
  /**
7
- * Represents the state of the BookmarkProvider store.
7
+ * Internal state shape managed by the bookmark store.
8
+ *
9
+ * @property status - Set of base action types currently in-flight (used for loading indicators).
10
+ * @property errors - Map from base action type to the most recent error for that action.
11
+ * @property currentBookmark - The active bookmark, `null` when explicitly cleared, `undefined` before first set.
12
+ * @property bookmarks - Normalised record of bookmarks keyed by ID.
8
13
  */
9
14
  export type BookmarkState = {
10
15
  status: Set<ActionBaseType<BookmarkActions>>;
@@ -13,16 +18,20 @@ export type BookmarkState = {
13
18
  bookmarks: Record<string, BookmarkWithoutData>;
14
19
  };
15
20
  /**
16
- * Represents the store for bookmarks, which is a flow subject that manages the state and actions for bookmarks.
21
+ * A {@link FlowSubject} specialised for bookmark state and actions.
22
+ *
23
+ * Combines a Redux-style reducer with RxJS side-effect flows to manage
24
+ * bookmark CRUD operations, favourites, and current-bookmark selection.
17
25
  */
18
26
  export type BookmarkStore = FlowSubject<BookmarkState, BookmarkActions>;
19
27
  /**
20
- * Creates a new BookmarkStore instance with the provided initial state and client.
28
+ * Creates and returns a new {@link BookmarkStore} wired with the bookmark
29
+ * reducer and all API side-effect flows.
21
30
  *
22
- * @param args - An object containing the initial state and client for the bookmark store.
23
- * @param args.initial - The initial state for the bookmark store.
24
- * @param args.client - The IBookmarkClient instance to bookmark store flows.
25
- * @returns A new BookmarkStore instance.
31
+ * @param args - Initialisation options.
32
+ * @param args.initial - Optional partial state merged over the reducer defaults.
33
+ * @param args.client - The {@link IBookmarkClient} used by store flows for API calls.
34
+ * @returns A fully configured bookmark store.
26
35
  */
27
36
  export declare const createBookmarkStore: (args: {
28
37
  initial?: Partial<BookmarkState>;
@@ -4,6 +4,12 @@ import type { IEventModuleProvider } from '@equinor/fusion-framework-module-even
4
4
  import type { IBookmarkProvider } from './BookmarkProvider.interface';
5
5
  import type { IBookmarkClient } from './BookmarkClient.interface';
6
6
  import type { BookmarkModuleConfig } from './types';
7
+ /**
8
+ * Zod schema that validates the full {@link BookmarkModuleConfig} object.
9
+ *
10
+ * Used internally by {@link BookmarkModuleConfigurator} to verify the resolved
11
+ * configuration before the bookmark module is initialised.
12
+ */
7
13
  export declare const bookmarkConfigSchema: z.ZodObject<{
8
14
  log: z.ZodOptional<z.ZodCustom<ILogger, ILogger>>;
9
15
  logLevel: z.ZodOptional<z.ZodEnum<typeof LogLevel>>;
@@ -24,4 +30,11 @@ export declare const bookmarkConfigSchema: z.ZodObject<{
24
30
  application: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
25
31
  }, z.core.$strip>>>;
26
32
  }, z.core.$strip>;
33
+ /**
34
+ * Parses an unknown configuration object against {@link bookmarkConfigSchema}.
35
+ *
36
+ * @param config - The raw config value to validate.
37
+ * @returns A validated {@link BookmarkModuleConfig}.
38
+ * @throws {ZodError} When validation fails.
39
+ */
27
40
  export declare const parseBookmarkConfig: (config: unknown) => BookmarkModuleConfig;
@@ -5,14 +5,37 @@ import type { AppModule } from '@equinor/fusion-framework-module-app';
5
5
  import type { ContextModule } from '@equinor/fusion-framework-module-context';
6
6
  import { BookmarkModuleConfigurator } from './BookmarkConfigurator';
7
7
  import type { IBookmarkProvider } from './BookmarkProvider.interface';
8
+ /** String literal key used to register the bookmark module in the framework. */
8
9
  export type BookmarkModuleKey = 'bookmark';
10
+ /** The module key constant used to identify the bookmark module at runtime. */
9
11
  export declare const moduleKey: BookmarkModuleKey;
12
+ /**
13
+ * Type definition for the bookmark framework module.
14
+ *
15
+ * Declares the module key, provider interface, configurator class,
16
+ * and optional peer dependencies (event, services, app, context modules).
17
+ */
10
18
  export type BookmarkModule = Module<BookmarkModuleKey, IBookmarkProvider, BookmarkModuleConfigurator, [
11
19
  EventModule,
12
20
  ServicesModule,
13
21
  AppModule,
14
22
  ContextModule
15
23
  ]>;
24
+ /**
25
+ * Bookmark module definition for the Fusion Framework.
26
+ *
27
+ * Handles configuration, initialization (creating a {@link BookmarkProvider}),
28
+ * and disposal of the bookmark module lifecycle.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { enableBookmark } from '@equinor/fusion-framework-module-bookmark';
33
+ *
34
+ * const configure = (configurator) => {
35
+ * enableBookmark(configurator);
36
+ * };
37
+ * ```
38
+ */
16
39
  export declare const module: BookmarkModule;
17
40
  declare module '@equinor/fusion-framework-module' {
18
41
  interface Modules {
@@ -1,20 +1,24 @@
1
1
  import * as z from 'zod';
2
2
  import type { Bookmark, BookmarkData } from './types';
3
+ /** Zod schema for validating {@link BookmarkUser} objects. */
3
4
  export declare const bookmarkUserSchema: z.ZodObject<{
4
5
  id: z.ZodString;
5
6
  name: z.ZodString;
6
7
  mail: z.ZodOptional<z.ZodString>;
7
8
  }, z.core.$strip>;
9
+ /** Zod schema for validating {@link SourceSystem} objects on a bookmark. */
8
10
  export declare const bookmarkSourceSystemSchema: z.ZodObject<{
9
11
  identifier: z.ZodString;
10
12
  name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
11
13
  subSystem: z.ZodOptional<z.ZodNullable<z.ZodString>>;
12
14
  }, z.core.$strip>;
15
+ /** Zod schema for validating {@link BookmarkContext} objects. */
13
16
  export declare const bookmarkContextSchema: z.ZodObject<{
14
17
  id: z.ZodString;
15
18
  name: z.ZodOptional<z.ZodString>;
16
19
  type: z.ZodOptional<z.ZodString>;
17
20
  }, z.core.$strip>;
21
+ /** Zod schema for validating a {@link BookmarkWithoutData} (no payload). */
18
22
  export declare const bookmarkSchema: z.ZodObject<{
19
23
  id: z.ZodString;
20
24
  name: z.ZodString;
@@ -44,6 +48,7 @@ export declare const bookmarkSchema: z.ZodObject<{
44
48
  subSystem: z.ZodOptional<z.ZodNullable<z.ZodString>>;
45
49
  }, z.core.$strip>>>;
46
50
  }, z.core.$strip>;
51
+ /** Zod schema for validating an array of bookmarks. */
47
52
  export declare const bookmarksSchema: z.ZodArray<z.ZodObject<{
48
53
  id: z.ZodString;
49
54
  name: z.ZodString;
@@ -73,6 +78,15 @@ export declare const bookmarksSchema: z.ZodArray<z.ZodObject<{
73
78
  subSystem: z.ZodOptional<z.ZodNullable<z.ZodString>>;
74
79
  }, z.core.$strip>>>;
75
80
  }, z.core.$strip>>;
81
+ /**
82
+ * Creates a Zod schema for a {@link Bookmark} that includes a typed payload field.
83
+ *
84
+ * @template T - The bookmark payload data shape.
85
+ * @template S - Zod schema type for the payload.
86
+ * @param schema - Optional Zod schema to validate the payload. Defaults to
87
+ * `z.record(z.string(), z.unknown()).or(z.string()).optional()`.
88
+ * @returns A Zod object schema extending {@link bookmarkSchema} with a `payload` property.
89
+ */
76
90
  export declare const bookmarkWithDataSchema: <T extends BookmarkData = BookmarkData, S extends z.ZodSchema<T> = z.ZodSchema<T>>(schema?: S) => z.ZodObject<{
77
91
  id: z.ZodString;
78
92
  name: z.ZodString;
@@ -103,4 +117,12 @@ export declare const bookmarkWithDataSchema: <T extends BookmarkData = BookmarkD
103
117
  }, z.core.$strip>>>;
104
118
  payload: S;
105
119
  }, z.core.$strip>;
120
+ /**
121
+ * Parses an unknown value into a typed {@link Bookmark} using {@link bookmarkWithDataSchema}.
122
+ *
123
+ * @template T - The bookmark payload data shape.
124
+ * @param value - The raw value to parse.
125
+ * @returns The parsed bookmark object.
126
+ * @throws {ZodError} When validation fails.
127
+ */
106
128
  export declare const parseBookmark: <T extends BookmarkData>(value: unknown) => Bookmark<T>;
@@ -1,9 +1,27 @@
1
1
  import type { IModulesConfigurator } from '@equinor/fusion-framework-module';
2
2
  import type { BookmarkModuleConfigurator } from './BookmarkConfigurator';
3
3
  /**
4
- * Enables the Bookmark module
4
+ * Enables the bookmark module on a Fusion Framework module configurator.
5
5
  *
6
- * @param configurator - The configuration object for the modules.
7
- * @param callback - An optional callback function that receives the `BookmarkModuleConfigurator` instance, allowing for further configuration.
6
+ * This is the primary entry point for adding bookmark support to an application.
7
+ * Call it during the application’s configure phase to register the module.
8
+ * An optional callback allows further customisation of the bookmark configurator
9
+ * (source system, filters, custom client, etc.).
10
+ *
11
+ * @param configurator - The application’s module configurator instance.
12
+ * @param callback - Optional callback that receives the {@link BookmarkModuleConfigurator}
13
+ * for additional setup such as setting source system, filters, or a custom client.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { enableBookmark } from '@equinor/fusion-framework-module-bookmark';
18
+ *
19
+ * const configure = (configurator) => {
20
+ * enableBookmark(configurator, (builder) => {
21
+ * builder.setSourceSystem({ identifier: 'my-app', name: 'My App' });
22
+ * builder.setFilter('application', true);
23
+ * });
24
+ * };
25
+ * ```
8
26
  */
9
27
  export declare const enableBookmark: (configurator: IModulesConfigurator<any>, callback?: (builder: BookmarkModuleConfigurator) => void | Promise<void>) => void;
@@ -1 +1 @@
1
- export declare const version = "3.0.6";
1
+ export declare const version = "4.0.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-module-bookmark",
3
- "version": "3.0.6",
3
+ "version": "4.0.0",
4
4
  "description": "",
5
5
  "main": "./dist/esm/index.js",
6
6
  "types": "./dist/types/index.d.ts",
@@ -41,20 +41,19 @@
41
41
  "immer": "^11.0.0",
42
42
  "rxjs": "^7.8.1",
43
43
  "uuid": "^13.0.0",
44
- "@equinor/fusion-framework-module": "^5.0.6",
45
- "@equinor/fusion-log": "^1.1.8",
46
- "@equinor/fusion-observable": "^8.5.8",
47
- "@equinor/fusion-query": "^6.0.4"
44
+ "@equinor/fusion-framework-module": "^6.0.0",
45
+ "@equinor/fusion-observable": "^9.0.0",
46
+ "@equinor/fusion-query": "^7.0.0",
47
+ "@equinor/fusion-log": "^2.0.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@types/uuid": "^11.0.0",
51
- "typescript": "^5.8.2",
52
- "zod": "^4.1.8",
53
- "@equinor/fusion-framework-module-context": "^7.0.3",
54
- "@equinor/fusion-framework-module-app": "^7.4.1",
55
- "@equinor/fusion-framework-module-event": "^5.0.1",
56
- "@equinor/fusion-framework-module-services": "^7.2.1",
57
- "@equinor/fusion-framework-module-http": "^7.0.8"
50
+ "typescript": "^5.9.3",
51
+ "zod": "^4.3.6",
52
+ "@equinor/fusion-framework-module-context": "^8.0.0",
53
+ "@equinor/fusion-framework-module-event": "^6.0.0",
54
+ "@equinor/fusion-framework-module-services": "^8.0.0",
55
+ "@equinor/fusion-framework-module-app": "^8.0.0",
56
+ "@equinor/fusion-framework-module-http": "^8.0.0"
58
57
  },
59
58
  "scripts": {
60
59
  "build": "tsc -b"
@@ -128,18 +128,22 @@ export class BookmarkClient implements IBookmarkClient {
128
128
  });
129
129
  }
130
130
 
131
+ /** @inheritdoc */
131
132
  public getAllBookmarks(filter?: BookmarksFilter): ObservableInput<Bookmark[]> {
132
133
  return this.#queryBookmarks.query(filter).pipe(map((res) => res.value as Bookmark[]));
133
134
  }
134
135
 
136
+ /** @inheritdoc */
135
137
  public getBookmarkById(bookmarkId: string): ObservableInput<BookmarkWithoutData> {
136
138
  return this.#queryBookmark.query({ bookmarkId }).pipe(map((res) => res.value));
137
139
  }
138
140
 
141
+ /** @inheritdoc */
139
142
  public getBookmarkData<T extends BookmarkData>(bookmarkId: string): ObservableInput<T> {
140
143
  return this.#queryBookmarkData.query({ bookmarkId }).pipe(map((res): T => res.value as T));
141
144
  }
142
145
 
146
+ /** @inheritdoc */
143
147
  public setBookmarkData<T extends BookmarkData | null>(
144
148
  bookmarkId: string,
145
149
  data: T,
@@ -158,6 +162,7 @@ export class BookmarkClient implements IBookmarkClient {
158
162
  );
159
163
  }
160
164
 
165
+ /** @inheritdoc */
161
166
  public createBookmark<T extends BookmarkData>(
162
167
  newBookmark: BookmarkNew<T>,
163
168
  ): ObservableInput<Bookmark<T>> {
@@ -184,6 +189,7 @@ export class BookmarkClient implements IBookmarkClient {
184
189
  );
185
190
  }
186
191
 
192
+ /** @inheritdoc */
187
193
  public updateBookmark<T extends BookmarkData>(
188
194
  bookmarkId: string,
189
195
  updates: BookmarkUpdate<T>,
@@ -240,22 +246,26 @@ export class BookmarkClient implements IBookmarkClient {
240
246
  });
241
247
  }
242
248
 
249
+ /** @inheritdoc */
243
250
  public deleteBookmark(bookmarkId: string): ObservableInput<boolean> {
244
251
  return this.#api.delete('v1', { bookmarkId });
245
252
  }
246
253
 
254
+ /** @inheritdoc */
247
255
  public addBookmarkToFavorites(bookmarkId: string): ObservableInput<boolean> {
248
256
  return this.#api
249
257
  .addFavourite('v1', { bookmarkId })
250
258
  .pipe(tap(() => this.#queryBookmarks.invalidate()));
251
259
  }
252
260
 
261
+ /** @inheritdoc */
253
262
  public removeBookmarkFromFavorites(bookmarkId: string): ObservableInput<boolean> {
254
263
  return this.#api
255
264
  .removeFavourite('v1', { bookmarkId })
256
265
  .pipe(tap(() => this.#queryBookmarks.invalidate()));
257
266
  }
258
267
 
268
+ /** @inheritdoc */
259
269
  public isBookmarkFavorite(bookmarkId: string): ObservableInput<boolean> {
260
270
  return this.#api.isFavorite('v1', { bookmarkId });
261
271
  }
@@ -32,7 +32,14 @@ const parseInitialBookmarkConfigConfig = (initial?: unknown): BookmarkModuleConf
32
32
 
33
33
  /**
34
34
  * Configurator for the bookmark module.
35
- * This class provides a set of methods for configuring the bookmark module.
35
+ *
36
+ * Provides a builder-style API for setting the source system, bookmark client,
37
+ * context/application resolvers, filters, and parent provider before the module
38
+ * is initialised. Extends {@link BaseConfigBuilder} and produces a validated
39
+ * {@link BookmarkModuleConfig} at build time.
40
+ *
41
+ * In most cases you interact with this class through the callback provided to
42
+ * {@link enableBookmark} rather than instantiating it directly.
36
43
  */
37
44
  export class BookmarkModuleConfigurator extends BaseConfigBuilder<BookmarkModuleConfig> {
38
45
  #log?: ILogger;
@@ -128,4 +128,5 @@ export const bookmarkActions = {
128
128
  ),
129
129
  };
130
130
 
131
+ /** Union type of all action objects produced by {@link bookmarkActions}. */
131
132
  export type BookmarkActions = ActionTypes<typeof bookmarkActions>;
@@ -2,9 +2,17 @@ import type { ActionWithSuffix } from '@equinor/fusion-observable';
2
2
 
3
3
  import type { BookmarkActions } from './BookmarkProvider.actions';
4
4
 
5
+ /**
6
+ * Error thrown inside bookmark store flows (side-effect pipelines) when an
7
+ * API call or observable chain fails.
8
+ *
9
+ * Carries a reference to the originating request action so callers can
10
+ * correlate errors back to specific operations.
11
+ */
5
12
  export class BookmarkFlowError extends Error {
6
13
  constructor(
7
14
  message: string,
15
+ /** The request action that triggered the failed flow. */
8
16
  public readonly action: ActionWithSuffix<BookmarkActions, 'request'>,
9
17
  options?: ErrorOptions,
10
18
  ) {
@@ -13,6 +21,13 @@ export class BookmarkFlowError extends Error {
13
21
  }
14
22
  }
15
23
 
24
+ /**
25
+ * General-purpose error thrown by {@link BookmarkProvider} methods when a
26
+ * high-level operation (create, update, delete, set current, etc.) fails.
27
+ *
28
+ * Distinct from {@link BookmarkFlowError}, which is scoped to internal
29
+ * store flow pipelines.
30
+ */
16
31
  export class BookmarkProviderError extends Error {
17
32
  constructor(message: string, options?: ErrorOptions) {
18
33
  super(message, options);
@@ -5,16 +5,43 @@ import type { BookmarkNew, BookmarkUpdate } from './BookmarkClient.interface';
5
5
  import type { BookmarkProviderEventMap } from './BookmarkProvider.events';
6
6
  import type { BookmarkState } from './BookmarkProvider.store';
7
7
 
8
+ /**
9
+ * Arguments for creating a bookmark via {@link IBookmarkProvider.createBookmark}.
10
+ *
11
+ * Omits fields that the provider resolves automatically (`appKey`, `contextId`, `sourceSystem`),
12
+ * but allows the caller to override `appKey` if needed.
13
+ *
14
+ * @template T - The type of payload data stored in the bookmark.
15
+ */
8
16
  export type BookmarkCreateArgs<T extends BookmarkData = any> = Omit<
9
17
  BookmarkNew<T>,
10
18
  'appKey' | 'contextId' | 'sourceSystem'
11
19
  > &
12
20
  Partial<Pick<BookmarkNew<T>, 'appKey'>>;
13
21
 
22
+ /**
23
+ * Options that control how {@link IBookmarkProvider.updateBookmark} processes an update.
24
+ *
25
+ * @property excludePayloadGeneration - When `true`, skip running registered payload generators
26
+ * and send the update payload as-is. Useful when the caller has already computed the full payload.
27
+ */
14
28
  export type BookmarkUpdateOptions = {
15
29
  excludePayloadGeneration?: boolean;
16
30
  };
17
31
 
32
+ /**
33
+ * Callback registered with {@link IBookmarkProvider.addPayloadGenerator} that participates
34
+ * in building or transforming bookmark payload data during create and update operations.
35
+ *
36
+ * The `payload` argument is an Immer draft — mutate it in place rather than returning a new
37
+ * object. If the generator returns a value it will be used, but this is discouraged.
38
+ * Return `null` to signal that the bookmark payload should be cleared.
39
+ *
40
+ * @template TData - Shape of the bookmark payload.
41
+ * @param payload - The accumulated payload draft from previous generators (mutable).
42
+ * @param initial - The original payload before any generators ran (read-only reference).
43
+ * @returns A partial payload, `void` (when mutating the draft), or `null` to clear.
44
+ */
18
45
  export type BookmarkPayloadGenerator<TData extends BookmarkData = any> = (
19
46
  payload?: Partial<TData> | null,
20
47
  initial?: Partial<TData> | null,
@@ -124,6 +151,16 @@ export interface IBookmarkProvider {
124
151
  */
125
152
  isBookmarkInFavorites(bookmarkId: string): ObservableInput<boolean>;
126
153
 
154
+ /**
155
+ * Registers a payload generator that runs during bookmark create and update operations.
156
+ *
157
+ * Multiple generators can be registered and they execute sequentially, each receiving
158
+ * the accumulated payload from previous generators.
159
+ *
160
+ * @template TData - Shape of the bookmark payload.
161
+ * @param generator - The generator callback to register.
162
+ * @returns A disposal function that unregisters the generator when called.
163
+ */
127
164
  addPayloadGenerator<TData extends BookmarkData>(
128
165
  generator: BookmarkPayloadGenerator<TData>,
129
166
  ): VoidFunction;
@@ -3,14 +3,22 @@ import type { BookmarkState } from './BookmarkProvider.store';
3
3
  import type { Bookmark, BookmarkData } from './types';
4
4
 
5
5
  /**
6
- * Selects all bookmarks from the application state.
6
+ * Selects all bookmarks from the store state as an array.
7
+ *
8
+ * @param state - The current bookmark store state.
9
+ * @returns An array of all bookmarks.
7
10
  */
8
11
  export const bookmarksSelector = (state: BookmarkState): Bookmark[] => {
9
12
  return Object.values(state.bookmarks) as Bookmark[];
10
13
  };
11
14
 
12
15
  /**
13
- * Retrieves a bookmark from the state by its ID.
16
+ * Retrieves a single bookmark from the store state by its ID.
17
+ *
18
+ * @template T - The bookmark payload data shape.
19
+ * @param state - The current bookmark store state.
20
+ * @param id - The bookmark identifier to look up.
21
+ * @returns The matching bookmark, or `undefined` if not found.
14
22
  */
15
23
  export const bookmarkSelector = <T extends BookmarkData>(
16
24
  state: BookmarkState,
@@ -20,12 +28,11 @@ export const bookmarkSelector = <T extends BookmarkData>(
20
28
  };
21
29
 
22
30
  /**
23
- * Selects the active bookmark from the bookmark state.
24
- *
25
- * if there is an active bookmark, the function returns the bookmark data.
31
+ * Selects the currently active bookmark from the store state.
26
32
  *
27
- * if there is no active bookmark, the function returns null.
28
- * if the active bookmark was never set, the function returns undefined.
33
+ * @template T - The bookmark payload data shape.
34
+ * @param state - The current bookmark store state.
35
+ * @returns The active bookmark, `null` if explicitly cleared, or `undefined` if never set.
29
36
  */
30
37
  export const activeBookmarkSelector = <T extends BookmarkData>(
31
38
  state: BookmarkState,