@equinor/fusion-framework-module-bookmark 1.2.13 → 2.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 (113) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +242 -9
  3. package/dist/esm/BookmarkClient.interface.js +2 -0
  4. package/dist/esm/BookmarkClient.interface.js.map +1 -0
  5. package/dist/esm/BookmarkClient.js +174 -0
  6. package/dist/esm/BookmarkClient.js.map +1 -0
  7. package/dist/esm/BookmarkConfigurator.js +348 -0
  8. package/dist/esm/BookmarkConfigurator.js.map +1 -0
  9. package/dist/esm/BookmarkProvider.actions.js +60 -0
  10. package/dist/esm/BookmarkProvider.actions.js.map +1 -0
  11. package/dist/esm/BookmarkProvider.error.js +14 -0
  12. package/dist/esm/BookmarkProvider.error.js.map +1 -0
  13. package/dist/esm/BookmarkProvider.events.js +2 -0
  14. package/dist/esm/BookmarkProvider.events.js.map +1 -0
  15. package/dist/esm/BookmarkProvider.flows.js +219 -0
  16. package/dist/esm/BookmarkProvider.flows.js.map +1 -0
  17. package/dist/esm/BookmarkProvider.js +937 -0
  18. package/dist/esm/BookmarkProvider.js.map +1 -0
  19. package/dist/esm/BookmarkProvider.reducer.js +125 -0
  20. package/dist/esm/BookmarkProvider.reducer.js.map +1 -0
  21. package/dist/esm/BookmarkProvider.selectors.js +43 -0
  22. package/dist/esm/BookmarkProvider.selectors.js.map +1 -0
  23. package/dist/esm/BookmarkProvider.store.js +19 -0
  24. package/dist/esm/BookmarkProvider.store.js.map +1 -0
  25. package/dist/esm/bookmark-config.schema.js +30 -0
  26. package/dist/esm/bookmark-config.schema.js.map +1 -0
  27. package/dist/esm/bookmark-module.js +53 -0
  28. package/dist/esm/bookmark-module.js.map +1 -0
  29. package/dist/esm/bookmark.schemas.js +38 -0
  30. package/dist/esm/bookmark.schemas.js.map +1 -0
  31. package/dist/esm/enable-bookmark.js +20 -7
  32. package/dist/esm/enable-bookmark.js.map +1 -1
  33. package/dist/esm/index.js +3 -3
  34. package/dist/esm/index.js.map +1 -1
  35. package/dist/esm/version.js +1 -1
  36. package/dist/esm/version.js.map +1 -1
  37. package/dist/tsconfig.tsbuildinfo +1 -1
  38. package/dist/types/BookmarkClient.d.ts +42 -0
  39. package/dist/types/BookmarkClient.interface.d.ts +139 -0
  40. package/dist/types/BookmarkConfigurator.d.ts +100 -0
  41. package/dist/types/BookmarkProvider.actions.d.ts +525 -0
  42. package/dist/types/BookmarkProvider.d.ts +462 -0
  43. package/dist/types/BookmarkProvider.error.d.ts +9 -0
  44. package/dist/types/BookmarkProvider.events.d.ts +78 -0
  45. package/dist/types/BookmarkProvider.flows.d.ts +79 -0
  46. package/dist/types/BookmarkProvider.reducer.d.ts +302 -0
  47. package/dist/types/BookmarkProvider.selectors.d.ts +34 -0
  48. package/dist/types/BookmarkProvider.store.d.ts +30 -0
  49. package/dist/types/bookmark-config.schema.d.ts +118 -0
  50. package/dist/types/{module.d.ts → bookmark-module.d.ts} +3 -3
  51. package/dist/types/bookmark.schemas.d.ts +760 -0
  52. package/dist/types/enable-bookmark.d.ts +7 -6
  53. package/dist/types/index.d.ts +4 -3
  54. package/dist/types/types.d.ts +29 -65
  55. package/dist/types/version.d.ts +1 -1
  56. package/package.json +11 -5
  57. package/src/BookmarkClient.interface.ts +157 -0
  58. package/src/BookmarkClient.ts +226 -0
  59. package/src/BookmarkConfigurator.ts +374 -0
  60. package/src/BookmarkProvider.actions.ts +131 -0
  61. package/src/BookmarkProvider.error.ts +21 -0
  62. package/src/BookmarkProvider.events.ts +89 -0
  63. package/src/BookmarkProvider.flows.ts +426 -0
  64. package/src/BookmarkProvider.reducer.ts +141 -0
  65. package/src/BookmarkProvider.selectors.ts +55 -0
  66. package/src/BookmarkProvider.store.ts +52 -0
  67. package/src/BookmarkProvider.ts +1308 -0
  68. package/src/bookmark-config.schema.ts +41 -0
  69. package/src/bookmark-module.ts +70 -0
  70. package/src/bookmark.schemas.ts +50 -0
  71. package/src/enable-bookmark.ts +13 -20
  72. package/src/index.ts +15 -7
  73. package/src/types.ts +46 -73
  74. package/src/version.ts +1 -1
  75. package/dist/esm/bookmark-config-builder.js +0 -131
  76. package/dist/esm/bookmark-config-builder.js.map +0 -1
  77. package/dist/esm/bookmark-provider.js +0 -155
  78. package/dist/esm/bookmark-provider.js.map +0 -1
  79. package/dist/esm/client/bookmarkActions.js +0 -10
  80. package/dist/esm/client/bookmarkActions.js.map +0 -1
  81. package/dist/esm/client/bookmarkClient.js +0 -259
  82. package/dist/esm/client/bookmarkClient.js.map +0 -1
  83. package/dist/esm/client/bookmarkFlows.js +0 -31
  84. package/dist/esm/client/bookmarkFlows.js.map +0 -1
  85. package/dist/esm/client/bookmarkReducer.js +0 -29
  86. package/dist/esm/client/bookmarkReducer.js.map +0 -1
  87. package/dist/esm/configurator.js +0 -155
  88. package/dist/esm/configurator.js.map +0 -1
  89. package/dist/esm/module.js +0 -27
  90. package/dist/esm/module.js.map +0 -1
  91. package/dist/esm/utils/handle-url.js +0 -11
  92. package/dist/esm/utils/handle-url.js.map +0 -1
  93. package/dist/esm/utils/index.js +0 -2
  94. package/dist/esm/utils/index.js.map +0 -1
  95. package/dist/types/bookmark-config-builder.d.ts +0 -85
  96. package/dist/types/bookmark-provider.d.ts +0 -169
  97. package/dist/types/client/bookmarkActions.d.ts +0 -27
  98. package/dist/types/client/bookmarkClient.d.ts +0 -53
  99. package/dist/types/client/bookmarkFlows.d.ts +0 -22
  100. package/dist/types/client/bookmarkReducer.d.ts +0 -5
  101. package/dist/types/configurator.d.ts +0 -75
  102. package/dist/types/utils/handle-url.d.ts +0 -2
  103. package/dist/types/utils/index.d.ts +0 -1
  104. package/src/bookmark-config-builder.ts +0 -177
  105. package/src/bookmark-provider.ts +0 -344
  106. package/src/client/bookmarkActions.ts +0 -44
  107. package/src/client/bookmarkClient.ts +0 -327
  108. package/src/client/bookmarkFlows.ts +0 -67
  109. package/src/client/bookmarkReducer.ts +0 -35
  110. package/src/configurator.ts +0 -235
  111. package/src/module.ts +0 -40
  112. package/src/utils/handle-url.ts +0 -13
  113. package/src/utils/index.ts +0 -1
@@ -0,0 +1,374 @@
1
+ import { z, ZodError } from 'zod';
2
+
3
+ import {
4
+ BaseConfigBuilder,
5
+ type ConfigBuilderCallback,
6
+ type ConfigBuilderCallbackArgs,
7
+ type ModulesInstanceType,
8
+ } from '@equinor/fusion-framework-module';
9
+
10
+ import type { IApiProvider, ServicesModule } from '@equinor/fusion-framework-module-services';
11
+ import type { AppModuleProvider } from '@equinor/fusion-framework-module-app';
12
+ import { type ILogger, LogLevel } from '@equinor/fusion-log';
13
+
14
+ import { BookmarkClient } from './BookmarkClient';
15
+ import type { BookmarkModule } from './bookmark-module';
16
+ import { bookmarkConfigSchema } from './bookmark-config.schema';
17
+ import type { BookmarkModuleConfig } from './types';
18
+
19
+ const initialBookmarkConfig = bookmarkConfigSchema
20
+ .pick({
21
+ filters: true,
22
+ sourceSystem: true,
23
+ resolve: true,
24
+ })
25
+ .partial()
26
+ .optional();
27
+
28
+ type InitialBookmarkConfig = z.infer<typeof initialBookmarkConfig>;
29
+
30
+ /**
31
+ * Configurator for the bookmark module.
32
+ * This class provides a set of methods for configuring the bookmark module.
33
+ */
34
+ export class BookmarkModuleConfigurator extends BaseConfigBuilder<BookmarkModuleConfig> {
35
+ #log?: ILogger;
36
+ defaultExpireTime = 1 * 60 * 1000; // Default expiration time for bookmarks
37
+
38
+ constructor(options?: { log?: ILogger; ref?: ModulesInstanceType<[BookmarkModule]> }) {
39
+ super();
40
+ const { log } = options ?? {};
41
+ this.#log = log;
42
+ this._set('log', async () => log);
43
+ }
44
+
45
+ /**
46
+ * Sets the log level for the bookmark configurator.
47
+ *
48
+ * @param level - The log level to set. Allowed values are:
49
+ * - 0: No logging
50
+ * - 1: Error messages only
51
+ * - 2: Error and warning messages
52
+ * - 3: Error, warning, and info messages
53
+ * - 4: Error, warning, info, and debug messages
54
+ */
55
+ public setLogLevel(level: LogLevel) {
56
+ this._set('logLevel', async () => level);
57
+ if (this.#log) {
58
+ this.#log.level = level;
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Sets the client for interacting with bookmark operations.
64
+ * The client argument can be either a client object with predefined methods for bookmark operations or a callback function that creates and returns such a client object.
65
+ * This method enables the configuration of how the bookmark module interacts with the backend or any other service to perform operations such as getting, creating, or updating bookmarks.
66
+ *
67
+ * @param client A client object or a callback function that returns a client object.
68
+ * - If a callback function is provided, it receives an initializer function as its argument,
69
+ * and it should return a Promise that resolves to a client object.
70
+ * - If a client object is provided directly, it is wrapped in a Promise and used as-is.
71
+ *
72
+ * @see {@link BookmarkModuleConfig.client}
73
+ */
74
+ public setClient(
75
+ client:
76
+ | ConfigBuilderCallback<BookmarkModuleConfig['client']>
77
+ | BookmarkModuleConfig['client'],
78
+ ) {
79
+ if (typeof client === 'function') {
80
+ this._set('client', (init) => client(init));
81
+ } else {
82
+ this._set('client', async () => client);
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Sets the parent configuration for the bookmark module.
88
+ * This allows the bookmark module to inherit configuration from a parent module.
89
+ *
90
+ * @param parent - A callback function or a configuration object that provides the parent configuration.
91
+ * - If a callback function is provided, it receives an initializer function as its argument and should return a Promise that resolves to the parent configuration object.
92
+ * - If a configuration object is provided directly, it is wrapped in a Promise and used as-is.
93
+ */
94
+ public setParent(
95
+ parent:
96
+ | ConfigBuilderCallback<BookmarkModuleConfig['parent']>
97
+ | BookmarkModuleConfig['parent'],
98
+ ) {
99
+ if (typeof parent === 'function') {
100
+ this._set('parent', (init) => parent(init));
101
+ } else {
102
+ this._set('parent', async () => parent);
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Set the source system for the bookmark module.
108
+ * This is used to tag bookmarks with their originating system for filtering or categorization purposes.
109
+ * @param sourceSystem - A callback function that returns the source system or a string value of the source system.
110
+ *
111
+ * Example:
112
+ * ```
113
+ * configurator.setSourceSystem('MyApplication');
114
+ * ```
115
+ * or
116
+ * ```
117
+ * configurator.setSourceSystem((init) => 'MyApplication');
118
+ * ```
119
+ */
120
+ public setSourceSystem(
121
+ sourceSystem:
122
+ | ConfigBuilderCallback<BookmarkModuleConfig['sourceSystem']>
123
+ | BookmarkModuleConfig['sourceSystem'],
124
+ ) {
125
+ if (typeof sourceSystem === 'function') {
126
+ this._set('sourceSystem', sourceSystem);
127
+ } else {
128
+ this._set('sourceSystem', async () => sourceSystem);
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Set the context ID resolver for the bookmark module.
134
+ * This function is used to resolve the context ID dynamically, allowing for context-aware bookmark operations.
135
+ * @param cb - A callback function that returns the context ID resolver function.
136
+ *
137
+ * Example:
138
+ * ```
139
+ * configurator.setContextIdResolver((init) => () => 'currentContextId');
140
+ * ```
141
+ */
142
+ public setContextResolver(
143
+ cb: ConfigBuilderCallback<BookmarkModuleConfig['resolve']['context']>,
144
+ ) {
145
+ this._set('resolve.context', cb);
146
+ }
147
+
148
+ /**
149
+ * Set the application key resolver for the bookmark module.
150
+ * This function is used to resolve the application key dynamically, providing a way to associate bookmarks with specific applications.
151
+ * @param cb - A callback function that returns the application key resolver function.
152
+ *
153
+ * Example:
154
+ * ```
155
+ * configurator.setApplicationKeyResolver((init) => () => 'myApplicationKey');
156
+ * ```
157
+ */
158
+ public setApplicationResolver(
159
+ cb: ConfigBuilderCallback<BookmarkModuleConfig['resolve']['application']>,
160
+ ) {
161
+ this._set('resolve.application', cb);
162
+ }
163
+
164
+ /**
165
+ * Sets a filter for the bookmark module.
166
+ * @param key - The key of the filter to set.
167
+ * @param value - The value to set for the filter.
168
+ *
169
+ * Applied when fetching bookmarks
170
+ * - application: Only return bookmarks for the resolved application.
171
+ * - context: Only return bookmarks for the resolved context.
172
+ */
173
+ public setFilter<TKey extends keyof BookmarkModuleConfig['filters']>(
174
+ key: TKey,
175
+ value: BookmarkModuleConfig['filters'][TKey],
176
+ ) {
177
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
178
+ // @ts-ignore
179
+ this._set(`filters.${key}`, async () => value);
180
+ }
181
+
182
+ /**
183
+ * Will set default configuration:
184
+ * - `client` - a default client is set
185
+ * - `resolveContextId` - a default context resolver is set
186
+ * - `resolveApplicationKey` - a default application key resolver is set
187
+ * - `sourceSystem` - a default source system is set
188
+ * @internal method to create config, will apply defaults if not provided during build of config.
189
+ * @param init - The config builder callback args.
190
+ * @param initial - An optional initial config to merge into the returned config.
191
+ * @returns The config object.
192
+ */
193
+ protected _createConfig(init: ConfigBuilderCallbackArgs, initial?: InitialBookmarkConfig) {
194
+ // check if parent is provided
195
+ if (!this._has('parent')) {
196
+ this.#log?.debug('No parent provided, using default parent');
197
+
198
+ // Check if parent and parent version compatible
199
+ const parentModules = init.ref as ModulesInstanceType<[BookmarkModule]>;
200
+ if (parentModules && 'bookmark' in parentModules) {
201
+ const parent = parentModules.bookmark;
202
+ if ('version' in parent && parent.version.satisfies('>=2.0.0')) {
203
+ this._set('parent', async () => parent);
204
+ } else {
205
+ this.#log?.warn('invalid version of parent BookmarkProvider provided');
206
+ }
207
+ } else {
208
+ this.#log?.info('No parent BookmarkProvider found');
209
+ }
210
+ }
211
+
212
+ // Ensure a default client is set if none is provided
213
+ if (!this._has('client')) {
214
+ this.#log?.debug('No client provided, using default client');
215
+ this._set('client', this._createDefaultClient.bind(this));
216
+ }
217
+
218
+ // Ensure a default context resolver is set if none is provided
219
+ if (!this._has('resolve.context')) {
220
+ this.#log?.debug('No context resolver provided, using default context resolver');
221
+ this._set('resolve.context', this._createDefaultContextResolver.bind(this));
222
+ }
223
+
224
+ // Ensure a default application resolver is set if none is provided
225
+ if (!this._has('resolve.application')) {
226
+ this.#log?.debug(
227
+ 'No application resolver provided, using default application resolver',
228
+ );
229
+ this._set('resolve.application', this._createDefaultApplicationResolver.bind(this));
230
+ }
231
+
232
+ // Ensure a default event provider is set if none is provided
233
+ if (!this._has('eventProvider')) {
234
+ this.#log?.debug('No event provider provided, using default event provider');
235
+ this._set('eventProvider', this._resolveEventProvider.bind(this));
236
+ }
237
+
238
+ // call super to create config
239
+ return super._createConfig(init, initialBookmarkConfig.parse(initial));
240
+ }
241
+
242
+ /**
243
+ * @internal Create a default context resolver for the bookmark module.
244
+ * @param init - The configuration initialization object.
245
+ * @returns A function that resolves the current context ID, or undefined if no context module is available.
246
+ */
247
+ protected async _createDefaultContextResolver(
248
+ init: ConfigBuilderCallbackArgs,
249
+ ): Promise<BookmarkModuleConfig['resolve']['context'] | void> {
250
+ // Check if context module is available and use context provider if available
251
+ if (init.hasModule('context')) {
252
+ this.#log?.debug('Context module available, awaiting instance');
253
+ const contextProvider = await init.requireInstance('context');
254
+
255
+ this.#log?.debug('Context provider available, creating context resolver');
256
+ return async () => {
257
+ this.#log?.debug('Resolving context for bookmarks');
258
+ const id = contextProvider.currentContext?.id;
259
+ return id ? { id } : undefined;
260
+ };
261
+ }
262
+ }
263
+
264
+ /**
265
+ * @internal Create a default application resolver for the bookmark module.
266
+ * @param init - The configuration initialization object.
267
+ * @returns A function that resolves the current application key, or undefined if no app module is available.
268
+ */
269
+ protected async _createDefaultApplicationResolver(
270
+ init: ConfigBuilderCallbackArgs,
271
+ ): Promise<BookmarkModuleConfig['resolve']['application'] | void> {
272
+ // Check if app module is available and use app provider if available
273
+ if (init.hasModule('app')) {
274
+ this.#log?.debug('App module available, awaiting instance');
275
+ const appProvider = await init.requireInstance('app');
276
+
277
+ this.#log?.debug('App provider available, creating application resolver');
278
+ return async () => {
279
+ const app = appProvider.current;
280
+ if (app) {
281
+ return {
282
+ appKey: app.appKey,
283
+ name: app.manifest?.name,
284
+ };
285
+ }
286
+ this.#log?.warn('No current application found');
287
+ return undefined;
288
+ };
289
+ }
290
+ }
291
+
292
+ protected async _resolveAppProvider(
293
+ init: ConfigBuilderCallbackArgs,
294
+ ): Promise<AppModuleProvider | undefined> {
295
+ // Check if app module is available
296
+ if (init.hasModule('app')) {
297
+ this.#log?.debug('App module available, awaiting instance');
298
+ return init.requireInstance('app');
299
+ }
300
+ this.#log?.debug('No app module available, will use ref to app module if available');
301
+ return undefined;
302
+ }
303
+
304
+ /**
305
+ * @internal Create a default event provider for the bookmark module.
306
+ * @param init - The configuration initialization object.
307
+ * @returns A promise that resolves to the default event provider.
308
+ */
309
+ protected async _resolveEventProvider(
310
+ init: ConfigBuilderCallbackArgs,
311
+ ): Promise<BookmarkModuleConfig['eventProvider'] | void> {
312
+ // Check if event module is available
313
+ if (init.hasModule('event')) {
314
+ this.#log?.debug('Event module available, awaiting instance');
315
+ return init.requireInstance('event');
316
+ }
317
+ }
318
+
319
+ /**
320
+ * @internal Create a default client for the bookmark module.
321
+ * @param init - The configuration initialization object.
322
+ * @returns A promise that resolves to the default client.
323
+ */
324
+ protected async _createDefaultClient(
325
+ init: ConfigBuilderCallbackArgs,
326
+ ): Promise<BookmarkModuleConfig['client'] | void> {
327
+ try {
328
+ const apiProvider = await this._getServiceProvider(init);
329
+ const api = await apiProvider.createBookmarksClient('json$');
330
+ return new BookmarkClient(api);
331
+ } catch (err) {
332
+ this.#log?.warn('Failed to create bookmark api client');
333
+ }
334
+ }
335
+
336
+ /**
337
+ * @internal retrieves the service provider from the configuration initialization object.
338
+ * @param init - The configuration initialization object.
339
+ * @returns A promise that resolves to the service provider.
340
+ */
341
+ protected async _getServiceProvider(init: ConfigBuilderCallbackArgs): Promise<IApiProvider> {
342
+ // check if services module is available
343
+ if (init.hasModule('services')) {
344
+ this.#log?.debug('Services module available, awaiting instance');
345
+ return init.requireInstance('services');
346
+ }
347
+
348
+ this.#log?.debug('No services module available, will use ref services module if available');
349
+
350
+ // check if parent has services module
351
+ const parentServiceModule = (init.ref as ModulesInstanceType<[ServicesModule]>)?.services;
352
+ if (parentServiceModule) {
353
+ return parentServiceModule;
354
+ }
355
+
356
+ // No service provider available
357
+ this.#log?.error('No service provider available, cannot create bookmarks client');
358
+ throw Error('[BookmarkConfigurator] No service provider configures [ServicesModule] ');
359
+ }
360
+
361
+ protected async _processConfig(
362
+ config: Partial<BookmarkModuleConfig>,
363
+ _init: ConfigBuilderCallbackArgs,
364
+ ): Promise<BookmarkModuleConfig> {
365
+ try {
366
+ return bookmarkConfigSchema.parse(config);
367
+ } catch (err) {
368
+ this.#log?.error('Failed to parse config', config, (err as ZodError).issues ?? err);
369
+ throw err;
370
+ }
371
+ }
372
+ }
373
+
374
+ export default BookmarkModuleConfigurator;
@@ -0,0 +1,131 @@
1
+ import {
2
+ Action,
3
+ createAction,
4
+ createAsyncAction,
5
+ type ActionTypes,
6
+ } from '@equinor/fusion-observable';
7
+
8
+ import type { Bookmark, BookmarkData, BookmarkWithoutData, Bookmarks } from './types';
9
+
10
+ import { BookmarkNew, BookmarkUpdate, type BookmarksFilter } from './BookmarkClient.interface';
11
+ import { type BookmarkFlowError } from './BookmarkProvider.error';
12
+
13
+ /**
14
+ * Represents the metadata associated with a bookmark action.
15
+ */
16
+ type BookmarkActionMeta = {
17
+ // A reference identifier for the request.
18
+ ref: string;
19
+ };
20
+
21
+ /**
22
+ * Actions related to the BookmarkProvider provider state.
23
+ *
24
+ * Exports a set of actions that can be used to manage bookmarks.
25
+ */
26
+ export const bookmarkActions = {
27
+ aborted: createAction('action_aborted', (action: Action) => ({
28
+ payload: action,
29
+ })),
30
+ setBookmark: createAction('update_bookmark', (bookmark: BookmarkWithoutData) => {
31
+ return { payload: bookmark };
32
+ }),
33
+ setCurrentBookmark: createAction('set_current_bookmark', (bookmark: Bookmark | null) => {
34
+ return { payload: bookmark };
35
+ }),
36
+ fetchBookmark: createAsyncAction(
37
+ 'fetch_bookmark',
38
+ (bookmarkId: string, meta?: BookmarkActionMeta) => ({
39
+ payload: bookmarkId,
40
+ meta,
41
+ }),
42
+ (bookmark: BookmarkWithoutData, meta?: BookmarkActionMeta) => ({ payload: bookmark, meta }),
43
+ (error: BookmarkFlowError, meta?: BookmarkActionMeta) => ({ payload: error, meta }),
44
+ ),
45
+ fetchBookmarkData: createAsyncAction(
46
+ 'fetch_bookmark_payload',
47
+ (bookmarkId: string, meta?: BookmarkActionMeta) => ({ payload: bookmarkId, meta }),
48
+ (bookmarkId: string, data: BookmarkData, meta?: BookmarkActionMeta) => ({
49
+ payload: { bookmarkId, data },
50
+ meta,
51
+ }),
52
+ (error: BookmarkFlowError, meta?: BookmarkActionMeta) => ({ payload: error, meta }),
53
+ ),
54
+ fetchBookmarks: createAsyncAction(
55
+ 'fetch_bookmarks',
56
+ (filter?: BookmarksFilter, meta?: BookmarkActionMeta) => ({ payload: filter, meta }),
57
+ (bookmarks: Bookmarks, meta?: BookmarkActionMeta) => ({ payload: bookmarks, meta }),
58
+ (error: BookmarkFlowError, meta?: BookmarkActionMeta) => ({ payload: error, meta }),
59
+ ),
60
+ updateBookmark: createAsyncAction(
61
+ 'update_bookmark',
62
+ (payload: { bookmarkId: string; updates: BookmarkUpdate }, meta: BookmarkActionMeta) => ({
63
+ payload,
64
+ meta,
65
+ }),
66
+ (payload: Bookmark, meta: BookmarkActionMeta) => ({ payload, meta }),
67
+ (payload: BookmarkFlowError, meta: BookmarkActionMeta) => ({ payload, meta }),
68
+ ),
69
+ createBookmark: createAsyncAction(
70
+ 'create_bookmark',
71
+ (payload: BookmarkNew, meta: BookmarkActionMeta) => ({ payload, meta }),
72
+ (payload: Bookmark, meta: BookmarkActionMeta) => ({ payload, meta }),
73
+ (payload: BookmarkFlowError, meta: BookmarkActionMeta) => ({ payload, meta }),
74
+ ),
75
+ deleteBookmark: createAsyncAction(
76
+ 'delete_bookmark',
77
+ (bookmarkId: string, meta?: BookmarkActionMeta) => ({
78
+ payload: bookmarkId,
79
+ meta: { ref: bookmarkId, ...meta },
80
+ }),
81
+ (bookmarkId: string, meta?: BookmarkActionMeta) => ({
82
+ payload: bookmarkId,
83
+ meta: { ref: bookmarkId, ...meta },
84
+ }),
85
+ (payload: BookmarkFlowError, meta: BookmarkActionMeta) => ({ payload, meta }),
86
+ ),
87
+ removeBookmark: createAsyncAction(
88
+ 'remove_bookmark',
89
+ (bookmarkId: string, meta?: BookmarkActionMeta) => ({
90
+ payload: bookmarkId,
91
+ meta: { ref: bookmarkId, ...meta },
92
+ }),
93
+ (
94
+ payload: {
95
+ type: 'delete_bookmark' | 'remove_favourite_bookmark';
96
+ bookmarkId: string;
97
+ },
98
+ meta: BookmarkActionMeta,
99
+ ) => ({ payload, meta }),
100
+ (payload: BookmarkFlowError, meta: BookmarkActionMeta) => ({
101
+ payload,
102
+ meta,
103
+ }),
104
+ ),
105
+ addBookmarkAsFavourite: createAsyncAction(
106
+ 'add_favourite_bookmark',
107
+ (bookmarkId: string, meta?: BookmarkActionMeta) => ({
108
+ payload: bookmarkId,
109
+ meta: { ref: bookmarkId, ...meta },
110
+ }),
111
+ (bookmarkId: string, meta?: BookmarkActionMeta) => ({
112
+ payload: bookmarkId,
113
+ meta: { ref: bookmarkId, ...meta },
114
+ }),
115
+ (error: BookmarkFlowError, meta: BookmarkActionMeta) => ({ payload: error, meta }),
116
+ ),
117
+ removeBookmarkAsFavourite: createAsyncAction(
118
+ 'remove_favourite_bookmark',
119
+ (bookmarkId: string, meta?: BookmarkActionMeta) => ({
120
+ payload: bookmarkId,
121
+ meta: { ref: bookmarkId, ...meta },
122
+ }),
123
+ (bookmarkId: string, meta?: BookmarkActionMeta) => ({
124
+ payload: bookmarkId,
125
+ meta: { ref: bookmarkId, ...meta },
126
+ }),
127
+ (error: BookmarkFlowError, meta: BookmarkActionMeta) => ({ payload: error, meta }),
128
+ ),
129
+ };
130
+
131
+ export type BookmarkActions = ActionTypes<typeof bookmarkActions>;
@@ -0,0 +1,21 @@
1
+ import { type ActionWithSuffix } from '@equinor/fusion-observable';
2
+
3
+ import { BookmarkActions } from './BookmarkProvider.actions';
4
+
5
+ export class BookmarkFlowError extends Error {
6
+ constructor(
7
+ message: string,
8
+ public readonly action: ActionWithSuffix<BookmarkActions, 'request'>,
9
+ options?: ErrorOptions,
10
+ ) {
11
+ super(message, options);
12
+ this.name = 'BookmarkProcessError';
13
+ }
14
+ }
15
+
16
+ export class BookmarkProviderError extends Error {
17
+ constructor(message: string, options?: ErrorOptions) {
18
+ super(message, options);
19
+ this.name = 'BookmarkProviderError';
20
+ }
21
+ }
@@ -0,0 +1,89 @@
1
+ import type { FrameworkEventInit, IFrameworkEvent } from '@equinor/fusion-framework-module-event';
2
+ import type { Bookmark } from './types';
3
+ import type { BookmarkPayloadGenerator, BookmarkProvider } from './BookmarkProvider';
4
+ import { BookmarkNew, BookmarkUpdate } from './BookmarkClient.interface';
5
+
6
+ export interface BookmarkProviderEventMap {
7
+ /**
8
+ * An event that is emitted before current bookmark is changed.
9
+ */
10
+ onCurrentBookmarkChange: IFrameworkEvent<
11
+ FrameworkEventInit<{ current?: Bookmark | null; next: Bookmark | null }, BookmarkProvider>
12
+ >;
13
+
14
+ /**
15
+ * An event that is emitted when the current bookmark has changed.
16
+ */
17
+ onCurrentBookmarkChanged: IFrameworkEvent<
18
+ FrameworkEventInit<Bookmark | null, BookmarkProvider>
19
+ >;
20
+
21
+ /**
22
+ * An event that is emitted before a bookmark is created.
23
+ */
24
+ onBookmarkCreate: IFrameworkEvent<FrameworkEventInit<BookmarkNew, BookmarkProvider>>;
25
+
26
+ /**
27
+ * An event that is emitted when a bookmark has been created.
28
+ */
29
+ onBookmarkCreated: IFrameworkEvent<FrameworkEventInit<Bookmark, BookmarkProvider>>;
30
+
31
+ /**
32
+ * An event that is emitted before a bookmark is updated.
33
+ */
34
+ onBookmarkUpdate: IFrameworkEvent<
35
+ FrameworkEventInit<{ current?: Bookmark; updates: BookmarkUpdate }, BookmarkProvider>
36
+ >;
37
+
38
+ /**
39
+ * An event that is emitted before a bookmark is updated.
40
+ */
41
+ onBookmarkUpdated: IFrameworkEvent<FrameworkEventInit<Bookmark, BookmarkProvider>>;
42
+
43
+ /**
44
+ * An event that is emitted before a bookmark is removed.
45
+ */
46
+ onBookmarkDelete: IFrameworkEvent<FrameworkEventInit<{ id: string }, BookmarkProvider>>;
47
+
48
+ /**
49
+ * An event that is emitted before a bookmark is removed.
50
+ */
51
+ onBookmarkDeleted: IFrameworkEvent<FrameworkEventInit<{ id: string }, BookmarkProvider>>;
52
+
53
+ /**
54
+ * An event that is emitted before a bookmark is added to the user's favorites.
55
+ */
56
+ onBookmarkFavouriteRemove: IFrameworkEvent<
57
+ FrameworkEventInit<{ id: string }, BookmarkProvider>
58
+ >;
59
+
60
+ /**
61
+ * An event that is emitted when a bookmark is removed from the user's favorites.
62
+ */
63
+ onBookmarkFavouriteRemoved: IFrameworkEvent<
64
+ FrameworkEventInit<{ id: string }, BookmarkProvider>
65
+ >;
66
+
67
+ /**
68
+ * An event that is emitted before a bookmark is added to the user's favorites.
69
+ */
70
+ onBookmarkFavouriteAdd: IFrameworkEvent<FrameworkEventInit<{ id: string }, BookmarkProvider>>;
71
+
72
+ /**
73
+ * An event that is emitted when a bookmark is added to the user's favorites.
74
+ */
75
+ onBookmarkFavouriteAdded: IFrameworkEvent<
76
+ FrameworkEventInit<Bookmark | undefined, BookmarkProvider>
77
+ >;
78
+
79
+ /**
80
+ * An event that is emitted when a new bookmark payload generator is added.
81
+ */
82
+ onBookmarkPayloadCreatorAdded: IFrameworkEvent<
83
+ FrameworkEventInit<BookmarkPayloadGenerator, BookmarkProvider>
84
+ >;
85
+ }
86
+
87
+ declare module '@equinor/fusion-framework-module-event' {
88
+ interface FrameworkEventMap extends BookmarkProviderEventMap {}
89
+ }