@coworkee/client 0.0.1095 → 0.0.1097
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/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/realtime.d.ts +36 -0
- package/dist/realtime.js +21 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ export { ApiError, problemMessage, problemOf, unwrap, type Problem } from './err
|
|
|
6
6
|
export { getUser, loginUrl, logout, type BffUser } from './bff.ts';
|
|
7
7
|
export { applyTheme, cssVariables, getCurrentTheme, logoUrl, palette, resolveMode, type ColorMode, type Theme } from './theme.ts';
|
|
8
8
|
export { format, getTexts, pickCulture, translator, type Texts, type Translate } from './texts.ts';
|
|
9
|
-
export { createRealtime, realtimeEvents, realtimeTopics, type EntityChanged, type Realtime, type RealtimeEnvelope, type RealtimeHandler } from './realtime.ts';
|
|
9
|
+
export { createRealtime, onEvent, realtimeEvents, realtimeTopics, targetedTopics, type ActorInfo, type EntityChanged, type Realtime, type RealtimeEnvelope, type RealtimeHandler, type Toast } from './realtime.ts';
|
|
10
10
|
export { lineSplitter, postNdjson } from './stream.ts';
|
|
11
11
|
export { entitySets, literal, odataPage, odataQuery, searchFilter, type EntitySetInfo, type ODataPage, type ODataQuery } from './odata.ts';
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,6 @@ export { ApiError, problemMessage, problemOf, unwrap } from "./errors.js";
|
|
|
3
3
|
export { getUser, loginUrl, logout } from "./bff.js";
|
|
4
4
|
export { applyTheme, cssVariables, getCurrentTheme, logoUrl, palette, resolveMode } from "./theme.js";
|
|
5
5
|
export { format, getTexts, pickCulture, translator } from "./texts.js";
|
|
6
|
-
export { createRealtime, realtimeEvents, realtimeTopics } from "./realtime.js";
|
|
6
|
+
export { createRealtime, onEvent, realtimeEvents, realtimeTopics, targetedTopics } from "./realtime.js";
|
|
7
7
|
export { lineSplitter, postNdjson } from "./stream.js";
|
|
8
8
|
export { entitySets, literal, odataPage, odataQuery, searchFilter } from "./odata.js";
|
package/dist/realtime.d.ts
CHANGED
|
@@ -4,6 +4,27 @@ export type RealtimeEnvelope<T = unknown> = {
|
|
|
4
4
|
topic: string;
|
|
5
5
|
type: string;
|
|
6
6
|
payload: T;
|
|
7
|
+
/** Metadata the server fills (older servers leave it out): unique id, when it was sent, who caused it (absent for the system), the request's trace. */
|
|
8
|
+
id?: string;
|
|
9
|
+
at?: string;
|
|
10
|
+
actor?: ActorInfo | null;
|
|
11
|
+
correlationId?: string | null;
|
|
12
|
+
};
|
|
13
|
+
/** Who caused an event; `impersonatorId` is set while someone is signed in as the user ("Log in as"). */
|
|
14
|
+
export type ActorInfo = {
|
|
15
|
+
userId?: string | null;
|
|
16
|
+
name?: string | null;
|
|
17
|
+
impersonatorId?: string | null;
|
|
18
|
+
};
|
|
19
|
+
/** A transient notification (`INotifier.ToastAsync`), on the user, session, organisation or global topic. */
|
|
20
|
+
export type Toast = {
|
|
21
|
+
title: string;
|
|
22
|
+
body?: string | null;
|
|
23
|
+
severity: 'Normal' | 'Info' | 'Success' | 'Warning' | 'Error';
|
|
24
|
+
link?: string | null;
|
|
25
|
+
/** Set for localizable texts: title and body are English texts with {0} placeholders. */
|
|
26
|
+
arguments?: string[] | null;
|
|
27
|
+
type?: string | null;
|
|
7
28
|
};
|
|
8
29
|
export type EntityChanged = {
|
|
9
30
|
entityType: string;
|
|
@@ -25,6 +46,10 @@ export declare const realtimeTopics: {
|
|
|
25
46
|
readonly presence: "tenant:presence";
|
|
26
47
|
readonly tenantPermissions: "tenant:permissions";
|
|
27
48
|
readonly globalPermissions: "global:permissions";
|
|
49
|
+
/** Events for the whole organisation (EventTarget.All) and for every organisation (EventTarget.Global). */
|
|
50
|
+
readonly tenantEvents: "tenant:events";
|
|
51
|
+
readonly globalEvents: "global:events";
|
|
52
|
+
readonly session: (sessionId: string) => string;
|
|
28
53
|
};
|
|
29
54
|
export declare const realtimeEvents: {
|
|
30
55
|
readonly entityChanged: "EntityChanged";
|
|
@@ -32,7 +57,18 @@ export declare const realtimeEvents: {
|
|
|
32
57
|
readonly presenceChanged: "presence.changed";
|
|
33
58
|
readonly chatMessage: "chat.message";
|
|
34
59
|
readonly chatRead: "chat.read";
|
|
60
|
+
readonly toast: "notification.toast";
|
|
35
61
|
};
|
|
62
|
+
/** The topics an event target of the server (EventTarget) reaches a signed-in user on: his own, the organisation's, the global one and his session's. */
|
|
63
|
+
export declare const targetedTopics: (userId: string, sessionId?: string) => string[];
|
|
64
|
+
/**
|
|
65
|
+
* Events of one type (an `[EventName]` of the server, `EntityChanged`, `notification.toast`) on the given topics, like `Realtime.On<T>` in Blazor:
|
|
66
|
+
* `onEvent<OrderApproved>(realtime, 'orders.approved', targetedTopics(me, sid), (e) => ...)`. `skipActor` leaves out what that user caused himself.
|
|
67
|
+
* The returned function stops every subscription.
|
|
68
|
+
*/
|
|
69
|
+
export declare function onEvent<T>(realtime: Realtime, type: string, topics: string[], handler: (payload: T, envelope: RealtimeEnvelope<T>) => void, options?: {
|
|
70
|
+
skipActor?: string;
|
|
71
|
+
}): () => void;
|
|
36
72
|
/**
|
|
37
73
|
* The realtime hub of the app (SignalR through the BFF, which adds the token). Connects on the first subscription and subscribes every
|
|
38
74
|
* followed topic again after a reconnect.
|
package/dist/realtime.js
CHANGED
|
@@ -7,8 +7,28 @@ export const realtimeTopics = {
|
|
|
7
7
|
presence: 'tenant:presence',
|
|
8
8
|
tenantPermissions: 'tenant:permissions',
|
|
9
9
|
globalPermissions: 'global:permissions',
|
|
10
|
+
/** Events for the whole organisation (EventTarget.All) and for every organisation (EventTarget.Global). */
|
|
11
|
+
tenantEvents: 'tenant:events',
|
|
12
|
+
globalEvents: 'global:events',
|
|
13
|
+
session: (sessionId) => `session:${sessionId}`,
|
|
10
14
|
};
|
|
11
|
-
export const realtimeEvents = { entityChanged: 'EntityChanged', sessionRevoked: 'SessionRevoked', presenceChanged: 'presence.changed', chatMessage: 'chat.message', chatRead: 'chat.read' };
|
|
15
|
+
export const realtimeEvents = { entityChanged: 'EntityChanged', sessionRevoked: 'SessionRevoked', presenceChanged: 'presence.changed', chatMessage: 'chat.message', chatRead: 'chat.read', toast: 'notification.toast' };
|
|
16
|
+
/** The topics an event target of the server (EventTarget) reaches a signed-in user on: his own, the organisation's, the global one and his session's. */
|
|
17
|
+
export const targetedTopics = (userId, sessionId) => [realtimeTopics.user(userId), realtimeTopics.tenantEvents, realtimeTopics.globalEvents, ...(sessionId ? [realtimeTopics.session(sessionId)] : [])];
|
|
18
|
+
/**
|
|
19
|
+
* Events of one type (an `[EventName]` of the server, `EntityChanged`, `notification.toast`) on the given topics, like `Realtime.On<T>` in Blazor:
|
|
20
|
+
* `onEvent<OrderApproved>(realtime, 'orders.approved', targetedTopics(me, sid), (e) => ...)`. `skipActor` leaves out what that user caused himself.
|
|
21
|
+
* The returned function stops every subscription.
|
|
22
|
+
*/
|
|
23
|
+
export function onEvent(realtime, type, topics, handler, options = {}) {
|
|
24
|
+
const receive = (envelope) => {
|
|
25
|
+
if (envelope.type !== type || (options.skipActor && envelope.actor?.userId === options.skipActor))
|
|
26
|
+
return;
|
|
27
|
+
handler(envelope.payload, envelope);
|
|
28
|
+
};
|
|
29
|
+
const stops = topics.map((topic) => realtime.subscribe(topic, receive));
|
|
30
|
+
return () => stops.forEach((stop) => stop());
|
|
31
|
+
}
|
|
12
32
|
/** Every retry after 0, 2, 10, then 30 seconds, forever - like the Blazor client. */
|
|
13
33
|
const delays = [0, 2000, 10000, 30000];
|
|
14
34
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coworkee/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1097",
|
|
4
4
|
"description": "Typed client for the API of Coworkee apps: OpenAPI types, BFF session, theme, texts and OData helpers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://framework.coworkee.de/web/airworks/",
|