@ovok/core 0.4.59-dev.564 → 0.4.59-dev.566

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 (31) hide show
  1. package/dist/client/cms/types.d.ts +23 -0
  2. package/dist/conformance/api-requirements.js +6 -0
  3. package/dist/conformance/capability-requirements.js +1 -1
  4. package/dist/next/index.d.ts +6 -0
  5. package/dist/next/ovok.d.ts +3 -0
  6. package/dist/next/ovok.js +2 -0
  7. package/dist/next/resources/chat/chat-catch-up.d.ts +26 -0
  8. package/dist/next/resources/chat/chat-catch-up.js +46 -0
  9. package/dist/next/resources/chat/chat-connection.d.ts +51 -0
  10. package/dist/next/resources/chat/chat-connection.js +188 -0
  11. package/dist/next/resources/chat/chat-errors.d.ts +4 -0
  12. package/dist/next/resources/chat/chat-errors.js +17 -0
  13. package/dist/next/resources/chat/chat-history.d.ts +16 -0
  14. package/dist/next/resources/chat/chat-history.js +49 -0
  15. package/dist/next/resources/chat/chat-messages-resource.d.ts +25 -0
  16. package/dist/next/resources/chat/chat-messages-resource.js +42 -0
  17. package/dist/next/resources/chat/chat-resource.d.ts +44 -0
  18. package/dist/next/resources/chat/chat-resource.js +49 -0
  19. package/dist/next/resources/chat/chat-threads-resource.d.ts +26 -0
  20. package/dist/next/resources/chat/chat-threads-resource.js +44 -0
  21. package/dist/next/resources/chat/chat-types.d.ts +157 -0
  22. package/dist/next/resources/chat/chat-types.js +2 -0
  23. package/dist/next/resources/cms/cms-authoring-resource.d.ts +49 -0
  24. package/dist/next/resources/cms/cms-authoring-resource.js +46 -0
  25. package/dist/next/resources/cms/cms-delivery.d.ts +2 -1
  26. package/dist/next/resources/cms/cms-delivery.js +9 -1
  27. package/dist/next/resources/cms/cms-resource.d.ts +13 -2
  28. package/dist/next/resources/cms/cms-resource.js +13 -1
  29. package/dist/next/resources/documents/documents-resource.d.ts +1 -1
  30. package/dist/next/resources/documents/documents-resource.js +4 -2
  31. package/package.json +4 -1
@@ -53,6 +53,29 @@ export type OvokCmsPage<T = OvokCmsDocument> = {
53
53
  /** `null` on the last page. */
54
54
  nextPage: number | null;
55
55
  };
56
+ /**
57
+ * A published item of a content type defined in the Console. `data` holds its fields, keyed by each field's `key`.
58
+ *
59
+ * @category cms
60
+ */
61
+ export type OvokCmsContentItem<T extends object = Record<string, unknown>> = {
62
+ /** Item id. */
63
+ id: number | string;
64
+ /** The content type: its id, or the type itself when the CMS fills it in. */
65
+ contentType: unknown;
66
+ /** Display title. */
67
+ title: string;
68
+ /** URL slug, unique within the content type; `null` when it has none. */
69
+ slug?: string | null;
70
+ /** Always `published` from the delivery API. */
71
+ status: string;
72
+ /** The field values, as written. */
73
+ data: T;
74
+ /** ISO 8601 creation time. */
75
+ createdAt?: string;
76
+ /** ISO 8601 time of the last change. */
77
+ updatedAt?: string;
78
+ };
56
79
  /**
57
80
  * Options shared by every CMS read.
58
81
  *
@@ -104,6 +104,12 @@ exports.OVOK_CORE_API_REQUIREMENTS = {
104
104
  { method: "GET", path: "/cms/:type/:language", group: "Content" },
105
105
  { method: "GET", path: "/v1/public/cms/collections/:collection/items", group: "Cms" },
106
106
  { method: "GET", path: "/v1/public/cms/collections/:collection/items/:slug", group: "Cms" },
107
+ { method: "GET", path: "/v1/public/cms/:contentTypeSlug/items", group: "Cms" },
108
+ { method: "GET", path: "/v1/content/:collection", group: "Cms" },
109
+ { method: "POST", path: "/v1/content/:collection", group: "Cms" },
110
+ { method: "GET", path: "/v1/content/:collection/:id", group: "Cms" },
111
+ { method: "PATCH", path: "/v1/content/:collection/:id", group: "Cms" },
112
+ { method: "DELETE", path: "/v1/content/:collection/:id", group: "Cms" },
107
113
  { method: "GET", path: "/video-call/livekit/access-permission/:appointmentId", group: "Video" },
108
114
  { method: "POST", path: "/video-call/livekit/guest-access/:appointmentId", group: "Video" },
109
115
  { method: "POST", path: "/video-call/livekit/user-access/:appointmentId", group: "Video" },
@@ -26,7 +26,7 @@ exports.OVOK_CORE_REQUIREMENTS = {
26
26
  description: "The FHIR surface a server must provide for the @ovok/core client library's own methods to function.",
27
27
  software: {
28
28
  name: "@ovok/core",
29
- version: "0.4.59-dev.564+6c0147c",
29
+ version: "0.4.59-dev.566+7e4647b",
30
30
  },
31
31
  fhirVersion: "4.0.1",
32
32
  format: ["json"],
@@ -46,11 +46,13 @@ export type { AiFhirSearchRequest } from "./resources/ai/ai-resource";
46
46
  export type { ChatSessionRetrieveParams } from "./resources/ai/chat-sessions-resource";
47
47
  export type { VideoCallAccessPermission } from "./resources/video-calls/video-call-access-resource";
48
48
  export type { ActiveCallNotification } from "./resources/video-calls/video-calls-resource";
49
+ export type { CmsAuthoringListParams, CmsWhere } from "./resources/cms/cms-authoring-resource";
49
50
  export type { CmsListParams, CmsReadParams } from "./resources/cms/cms-delivery";
50
51
  export type { DeletedDocument, DocumentDownloadParams } from "./resources/documents/documents-resource";
51
52
  export type { BotInput, BotOutput } from "./resources/bots/bots-resource";
52
53
  export type { PushDevice, PushDeviceList, PushPlatform, RegisterPushDeviceRequest, } from "./resources/push/push-devices-resource";
53
54
  export type { ApnsEnvironment, ApnsPushProvider, ApnsPushProviderChange, CreatePushProviderRequest, ExpoPushProvider, FcmPushProvider, PushProviderName, PushProviderSettings, RelayPushProvider, UpdatePushProviderRequest, } from "./resources/push/push-provider-resource";
55
+ export type { ChatEvent, ChatEventHandler, ChatMessage, ChatMessageListParams, ChatParticipant, ChatRead, ChatReadRequest, ChatStopListening, ChatThread, ChatThreadListParams, OpenChatThreadRequest, SendChatMessageRequest, } from "./resources/chat/chat-types";
54
56
  export type { NotificationsRule, NotificationsRuleResponse } from "./resources/omnichannel-alerts/notifications-rules-resource";
55
57
  export type { NotificationsPreviewAlert, NotificationsPreviewNotify, NotificationsPreviewRecipient, NotificationsPreviewRequest, NotificationsPreviewResponse, OmnichannelAlertEvent, } from "./resources/omnichannel-alerts/omnichannel-alerts-resource";
56
58
  export type * from "./resources/slim/slim-queries";
@@ -58,6 +60,10 @@ export type { AccountsResource } from "./resources/accounts/accounts-resource";
58
60
  export type { AiResource } from "./resources/ai/ai-resource";
59
61
  export type { AuthResource } from "./resources/auth-resource";
60
62
  export type { BotsResource } from "./resources/bots/bots-resource";
63
+ export type { ChatResource, ChatSettings } from "./resources/chat/chat-resource";
64
+ export type { ChatThreadMessagesResource } from "./resources/chat/chat-messages-resource";
65
+ export type { ChatThreadsResource } from "./resources/chat/chat-threads-resource";
66
+ export type { CmsAuthoringResource } from "./resources/cms/cms-authoring-resource";
61
67
  export type { CmsResource } from "./resources/cms/cms-resource";
62
68
  export type { ConsentResource } from "./resources/consent/consent-resource";
63
69
  export type { ContentResource } from "./resources/content/content-resource";
@@ -4,6 +4,7 @@ import { AccountsResource } from "./resources/accounts/accounts-resource";
4
4
  import { AiResource } from "./resources/ai/ai-resource";
5
5
  import { AuthResource } from "./resources/auth-resource";
6
6
  import { BotsResource } from "./resources/bots/bots-resource";
7
+ import { ChatResource } from "./resources/chat/chat-resource";
7
8
  import { CmsResource } from "./resources/cms/cms-resource";
8
9
  import { ConsentResource } from "./resources/consent/consent-resource";
9
10
  import { ContentResource } from "./resources/content/content-resource";
@@ -91,5 +92,7 @@ export declare class Ovok {
91
92
  readonly push: PushResource;
92
93
  /** The rule that decides who hears of each Signals alert, and its preview. */
93
94
  readonly omnichannelAlerts: OmnichannelAlertsResource;
95
+ /** Chat between patients and their care team. */
96
+ readonly chat: ChatResource;
94
97
  constructor(config: OvokConfig);
95
98
  }
package/dist/next/ovok.js CHANGED
@@ -13,6 +13,7 @@ const accounts_resource_1 = require("./resources/accounts/accounts-resource");
13
13
  const ai_resource_1 = require("./resources/ai/ai-resource");
14
14
  const auth_resource_1 = require("./resources/auth-resource");
15
15
  const bots_resource_1 = require("./resources/bots/bots-resource");
16
+ const chat_resource_1 = require("./resources/chat/chat-resource");
16
17
  const cms_resource_1 = require("./resources/cms/cms-resource");
17
18
  const consent_resource_1 = require("./resources/consent/consent-resource");
18
19
  const content_resource_1 = require("./resources/content/content-resource");
@@ -94,6 +95,7 @@ class Ovok {
94
95
  this.bots = new bots_resource_1.BotsResource(http);
95
96
  this.push = new push_resource_1.PushResource(http);
96
97
  this.omnichannelAlerts = new omnichannel_alerts_resource_1.OmnichannelAlertsResource(http);
98
+ this.chat = new chat_resource_1.ChatResource(http, this.session, settings);
97
99
  }
98
100
  }
99
101
  exports.Ovok = Ovok;
@@ -0,0 +1,26 @@
1
+ import { ScopedLogger } from "../../logging/ovok-logger";
2
+ import { ChatHistory } from "./chat-history";
3
+ import { ChatThreadMessagesResource } from "./chat-messages-resource";
4
+ import { ChatThreadsResource } from "./chat-threads-resource";
5
+ import { ChatMessage, ChatThread } from "./chat-types";
6
+ export type ChatCatchUpDependencies = {
7
+ threads: ChatThreadsResource;
8
+ messages: ChatThreadMessagesResource;
9
+ history: ChatHistory;
10
+ logger: ScopedLogger;
11
+ receiveThread: (thread: ChatThread) => void;
12
+ receiveMessage: (message: ChatMessage) => void;
13
+ };
14
+ /** Delivery on the socket is at-most-once, so what changed while it was down is read back from the REST routes. */
15
+ export declare class ChatCatchUp {
16
+ private readonly deps;
17
+ private pendingFrom;
18
+ private running;
19
+ constructor(deps: ChatCatchUpDependencies);
20
+ /** Runs one catch-up after any still running; a failed one starts from the same point next time. */
21
+ run(): Promise<void>;
22
+ reset(): void;
23
+ private catchUp;
24
+ /** The server pages newest first; missed messages are delivered oldest first. */
25
+ private catchUpThread;
26
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatCatchUp = void 0;
4
+ /** Delivery on the socket is at-most-once, so what changed while it was down is read back from the REST routes. */
5
+ class ChatCatchUp {
6
+ constructor(deps) {
7
+ this.deps = deps;
8
+ this.pendingFrom = null;
9
+ this.running = Promise.resolve();
10
+ }
11
+ /** Runs one catch-up after any still running; a failed one starts from the same point next time. */
12
+ run() {
13
+ this.running = this.running.then(() => this.catchUp());
14
+ return this.running;
15
+ }
16
+ reset() {
17
+ this.pendingFrom = null;
18
+ }
19
+ async catchUp() {
20
+ var _a;
21
+ const from = (_a = this.pendingFrom) !== null && _a !== void 0 ? _a : this.deps.history.watermark;
22
+ if (from === null) {
23
+ return;
24
+ }
25
+ this.pendingFrom = from;
26
+ try {
27
+ for await (const thread of this.deps.threads.list({ updatedSince: from })) {
28
+ this.deps.receiveThread(thread);
29
+ await this.catchUpThread(thread.id, from);
30
+ }
31
+ this.pendingFrom = null;
32
+ }
33
+ catch (error) {
34
+ this.deps.logger.warn("chat.catch_up.failed", { error: error instanceof Error ? error.name : "unknown" });
35
+ }
36
+ }
37
+ /** The server pages newest first; missed messages are delivered oldest first. */
38
+ async catchUpThread(threadId, since) {
39
+ const missed = [];
40
+ for await (const message of this.deps.messages.list(threadId, { since })) {
41
+ missed.push(message);
42
+ }
43
+ missed.reverse().forEach(this.deps.receiveMessage);
44
+ }
45
+ }
46
+ exports.ChatCatchUp = ChatCatchUp;
@@ -0,0 +1,51 @@
1
+ import type { ManagerOptions, Socket, SocketOptions } from "socket.io-client";
2
+ import { HttpClient } from "../../http/http-client";
3
+ import { ScopedLogger } from "../../logging/ovok-logger";
4
+ import { SessionResource } from "../session/session-resource";
5
+ import { ChatHistory } from "./chat-history";
6
+ import { ChatThreadMessagesResource } from "./chat-messages-resource";
7
+ import { ChatThreadsResource } from "./chat-threads-resource";
8
+ import { ChatEventHandler, ChatStopListening } from "./chat-types";
9
+ export type OpenSocket = (url: string, options: Partial<ManagerOptions & SocketOptions>) => Socket;
10
+ export type ChatConnectionDependencies = {
11
+ http: HttpClient;
12
+ session: SessionResource;
13
+ baseUrl: string;
14
+ threads: ChatThreadsResource;
15
+ messages: ChatThreadMessagesResource;
16
+ history: ChatHistory;
17
+ logger: ScopedLogger;
18
+ openSocket: OpenSocket;
19
+ };
20
+ /** One `/events` socket shared by every `listen` of a client, open while at least one listener is left. */
21
+ export declare class ChatConnection {
22
+ private readonly deps;
23
+ private readonly handlers;
24
+ private readonly catchUp;
25
+ private socket;
26
+ private ready;
27
+ private start;
28
+ private profile;
29
+ private stopWatchingSession;
30
+ private retryTimer;
31
+ private retries;
32
+ constructor(deps: ChatConnectionDependencies);
33
+ listen(handler: ChatEventHandler): Promise<ChatStopListening>;
34
+ private remove;
35
+ private open;
36
+ private connect;
37
+ private newSocket;
38
+ /** Every connection attempt spends a fresh single-use ticket, so the access token never travels on the socket. */
39
+ private sendTicket;
40
+ private subscribe;
41
+ /** A connection that came up but cannot be used is closed, so `reconnectLater` takes over from socket.io. */
42
+ private failed;
43
+ private connectFailed;
44
+ /** socket.io reconnects a dropped connection itself; a refused ticket or subscription needs a new attempt. */
45
+ private reconnectLater;
46
+ private receiveMessage;
47
+ private receiveThread;
48
+ private emit;
49
+ private signedOut;
50
+ private close;
51
+ }
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatConnection = void 0;
4
+ const ovok_errors_1 = require("../../errors/ovok-errors");
5
+ const chat_catch_up_1 = require("./chat-catch-up");
6
+ const chat_errors_1 = require("./chat-errors");
7
+ const chat_history_1 = require("./chat-history");
8
+ const EVENTS_NAMESPACE = "/events";
9
+ const TICKET_PATH = "v1/events/ticket";
10
+ const CHAT_TOPIC = "chat";
11
+ const SUBSCRIBE_TIMEOUT_MS = 10000;
12
+ const RECONNECT_DELAY_MS = 1000;
13
+ const RECONNECT_DELAY_MAX_MS = 30000;
14
+ const RECONNECT_JITTER = 0.5;
15
+ const reconnectDelay = (attempt) => {
16
+ const jitter = 1 + RECONNECT_JITTER * (Math.random() * 2 - 1);
17
+ return Math.min(RECONNECT_DELAY_MAX_MS, RECONNECT_DELAY_MS * 2 ** attempt) * jitter;
18
+ };
19
+ /** One `/events` socket shared by every `listen` of a client, open while at least one listener is left. */
20
+ class ChatConnection {
21
+ constructor(deps) {
22
+ this.deps = deps;
23
+ this.handlers = new Set();
24
+ this.socket = null;
25
+ this.ready = null;
26
+ this.start = null;
27
+ this.profile = null;
28
+ this.stopWatchingSession = null;
29
+ this.retryTimer = null;
30
+ this.retries = 0;
31
+ this.catchUp = new chat_catch_up_1.ChatCatchUp({
32
+ ...deps,
33
+ receiveThread: (thread) => this.receiveThread(thread),
34
+ receiveMessage: (message) => this.receiveMessage(message),
35
+ });
36
+ }
37
+ async listen(handler) {
38
+ const listener = (event) => handler(event);
39
+ this.handlers.add(listener);
40
+ try {
41
+ await this.open();
42
+ }
43
+ catch (error) {
44
+ this.handlers.delete(listener);
45
+ throw error;
46
+ }
47
+ return async () => this.remove(listener);
48
+ }
49
+ remove(listener) {
50
+ this.handlers.delete(listener);
51
+ if (this.handlers.size === 0) {
52
+ this.close();
53
+ }
54
+ }
55
+ open() {
56
+ var _a;
57
+ (_a = this.ready) !== null && _a !== void 0 ? _a : (this.ready = this.connect().catch((error) => {
58
+ this.close();
59
+ throw error;
60
+ }));
61
+ return this.ready;
62
+ }
63
+ async connect() {
64
+ var _a, _b;
65
+ this.profile = (_b = (_a = (await this.deps.session.current())) === null || _a === void 0 ? void 0 : _a.profile.reference) !== null && _b !== void 0 ? _b : null;
66
+ this.stopWatchingSession = this.deps.session.onChange((session) => {
67
+ var _a;
68
+ if (((_a = session === null || session === void 0 ? void 0 : session.profile.reference) !== null && _a !== void 0 ? _a : null) !== this.profile) {
69
+ this.signedOut();
70
+ }
71
+ });
72
+ return new Promise((resolve, reject) => {
73
+ this.start = { resolve, reject };
74
+ this.socket = this.newSocket();
75
+ this.socket.connect();
76
+ });
77
+ }
78
+ newSocket() {
79
+ const socket = this.deps.openSocket(new URL(EVENTS_NAMESPACE, this.deps.baseUrl).toString(), {
80
+ auth: (send) => this.sendTicket(socket, send),
81
+ autoConnect: false,
82
+ forceNew: true,
83
+ reconnectionDelay: RECONNECT_DELAY_MS,
84
+ reconnectionDelayMax: RECONNECT_DELAY_MAX_MS,
85
+ randomizationFactor: RECONNECT_JITTER,
86
+ });
87
+ socket.on("connect", () => void this.subscribe(socket));
88
+ socket.on("connect_error", (error) => this.connectFailed(socket, error));
89
+ socket.on("disconnect", () => this.reconnectLater(socket));
90
+ socket.on("subscription_ended", () => socket.disconnect());
91
+ socket.on("chat.message", (message) => this.receiveMessage(message));
92
+ socket.on("chat.read", (read) => this.emit({ type: "read", ...read }));
93
+ socket.on("chat.thread", (thread) => this.receiveThread(thread));
94
+ return socket;
95
+ }
96
+ /** Every connection attempt spends a fresh single-use ticket, so the access token never travels on the socket. */
97
+ sendTicket(socket, send) {
98
+ this.deps.http.post(TICKET_PATH).then(({ ticket }) => send({ ticket }), (error) => this.failed(socket, error));
99
+ }
100
+ async subscribe(socket) {
101
+ var _a;
102
+ try {
103
+ const answer = await socket
104
+ .timeout(SUBSCRIBE_TIMEOUT_MS)
105
+ .emitWithAck("subscribe", { topic: CHAT_TOPIC });
106
+ if ("error" in answer) {
107
+ throw (0, chat_errors_1.subscribeRefusal)(answer.error);
108
+ }
109
+ }
110
+ catch (error) {
111
+ this.failed(socket, error);
112
+ return;
113
+ }
114
+ this.retries = 0;
115
+ (_a = this.start) === null || _a === void 0 ? void 0 : _a.resolve();
116
+ await this.catchUp.run();
117
+ }
118
+ /** A connection that came up but cannot be used is closed, so `reconnectLater` takes over from socket.io. */
119
+ failed(socket, error) {
120
+ socket.disconnect();
121
+ this.connectFailed(socket, error);
122
+ }
123
+ connectFailed(socket, error) {
124
+ var _a;
125
+ if (socket !== this.socket) {
126
+ return;
127
+ }
128
+ const failure = (0, chat_errors_1.asOvokError)(error);
129
+ (_a = this.start) === null || _a === void 0 ? void 0 : _a.reject(failure);
130
+ this.deps.logger.warn("chat.listen.failed", { error: failure.name, status: failure.status });
131
+ this.reconnectLater(socket);
132
+ }
133
+ /** socket.io reconnects a dropped connection itself; a refused ticket or subscription needs a new attempt. */
134
+ reconnectLater(socket) {
135
+ if (socket !== this.socket || socket.active || this.retryTimer !== null) {
136
+ return;
137
+ }
138
+ this.retryTimer = setTimeout(() => {
139
+ this.retryTimer = null;
140
+ socket.connect();
141
+ }, reconnectDelay(this.retries));
142
+ this.retries += 1;
143
+ }
144
+ receiveMessage(message) {
145
+ if (this.deps.history.deliver(message)) {
146
+ this.emit({ type: "message", message });
147
+ }
148
+ }
149
+ receiveThread(thread) {
150
+ this.deps.history.observe((0, chat_history_1.activityOf)(thread));
151
+ this.emit({ type: "thread", thread });
152
+ }
153
+ emit(event) {
154
+ for (const handler of [...this.handlers]) {
155
+ try {
156
+ handler(event);
157
+ }
158
+ catch (error) {
159
+ const name = error instanceof Error ? error.name : "unknown";
160
+ this.deps.logger.error("chat.listen.handler_failed", { error: name, event: event.type });
161
+ }
162
+ }
163
+ }
164
+ signedOut() {
165
+ this.handlers.clear();
166
+ this.close();
167
+ this.deps.history.forget();
168
+ }
169
+ close() {
170
+ var _a, _b;
171
+ const socket = this.socket;
172
+ (_a = this.start) === null || _a === void 0 ? void 0 : _a.reject(new ovok_errors_1.OvokConnectionError((0, ovok_errors_1.detailsFor)("Chat stopped listening before it connected.")));
173
+ this.start = null;
174
+ this.socket = null;
175
+ this.ready = null;
176
+ this.retries = 0;
177
+ this.catchUp.reset();
178
+ (_b = this.stopWatchingSession) === null || _b === void 0 ? void 0 : _b.call(this);
179
+ this.stopWatchingSession = null;
180
+ if (this.retryTimer !== null) {
181
+ clearTimeout(this.retryTimer);
182
+ }
183
+ this.retryTimer = null;
184
+ socket === null || socket === void 0 ? void 0 : socket.off();
185
+ socket === null || socket === void 0 ? void 0 : socket.disconnect();
186
+ }
187
+ }
188
+ exports.ChatConnection = ChatConnection;
@@ -0,0 +1,4 @@
1
+ import { OvokError } from "../../errors/ovok-errors";
2
+ /** The `/events` gateway answers a refused `subscribe` with a code instead of a status. */
3
+ export declare const subscribeRefusal: (code: string) => OvokError;
4
+ export declare const asOvokError: (error: unknown) => OvokError;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asOvokError = exports.subscribeRefusal = void 0;
4
+ const ovok_errors_1 = require("../../errors/ovok-errors");
5
+ const SUBSCRIBE_REFUSALS = {
6
+ forbidden: ovok_errors_1.OvokPermissionError,
7
+ no_project: ovok_errors_1.OvokPermissionError,
8
+ };
9
+ /** The `/events` gateway answers a refused `subscribe` with a code instead of a status. */
10
+ const subscribeRefusal = (code) => {
11
+ var _a;
12
+ const ErrorClass = (_a = SUBSCRIBE_REFUSALS[code]) !== null && _a !== void 0 ? _a : ovok_errors_1.OvokServiceError;
13
+ return new ErrorClass({ ...(0, ovok_errors_1.detailsFor)(`The chat subscription was refused: ${code}.`), code });
14
+ };
15
+ exports.subscribeRefusal = subscribeRefusal;
16
+ const asOvokError = (error) => error instanceof ovok_errors_1.OvokError ? error : new ovok_errors_1.OvokConnectionError((0, ovok_errors_1.detailsFor)("Could not connect to chat events."), error);
17
+ exports.asOvokError = asOvokError;
@@ -0,0 +1,16 @@
1
+ import type { ChatMessage, ChatThread } from "./chat-types";
2
+ export declare const activityOf: (thread: ChatThread) => string;
3
+ /** The newest server time this client has seen in chat, and the messages `listen` has already delivered. */
4
+ export declare class ChatHistory {
5
+ private newest;
6
+ private readonly delivered;
7
+ get watermark(): string | null;
8
+ /** A read during a gap must not move the watermark past messages the gap hid, so reads only set the first one. */
9
+ seed(times: string[]): void;
10
+ observe(time: string): void;
11
+ /** Records the message as delivered; false when it already was. */
12
+ deliver(message: ChatMessage): boolean;
13
+ forget(): void;
14
+ /** Only recent ids matter: a catch-up re-reads just the messages after the watermark. */
15
+ private forgetOldest;
16
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatHistory = exports.activityOf = void 0;
4
+ const REMEMBERED_MESSAGES = 1000;
5
+ const isLater = (time, than) => Date.parse(time) > Date.parse(than);
6
+ const activityOf = (thread) => { var _a; return (_a = thread.lastMessageAt) !== null && _a !== void 0 ? _a : thread.createdAt; };
7
+ exports.activityOf = activityOf;
8
+ /** The newest server time this client has seen in chat, and the messages `listen` has already delivered. */
9
+ class ChatHistory {
10
+ constructor() {
11
+ this.newest = null;
12
+ this.delivered = new Set();
13
+ }
14
+ get watermark() {
15
+ return this.newest;
16
+ }
17
+ /** A read during a gap must not move the watermark past messages the gap hid, so reads only set the first one. */
18
+ seed(times) {
19
+ if (this.newest === null) {
20
+ times.forEach((time) => this.observe(time));
21
+ }
22
+ }
23
+ observe(time) {
24
+ if (this.newest === null || isLater(time, this.newest)) {
25
+ this.newest = time;
26
+ }
27
+ }
28
+ /** Records the message as delivered; false when it already was. */
29
+ deliver(message) {
30
+ if (this.delivered.has(message.id)) {
31
+ return false;
32
+ }
33
+ this.delivered.add(message.id);
34
+ this.forgetOldest();
35
+ this.observe(message.sentAt);
36
+ return true;
37
+ }
38
+ forget() {
39
+ this.newest = null;
40
+ this.delivered.clear();
41
+ }
42
+ /** Only recent ids matter: a catch-up re-reads just the messages after the watermark. */
43
+ forgetOldest() {
44
+ if (this.delivered.size > REMEMBERED_MESSAGES) {
45
+ this.delivered.delete(this.delivered.values().next().value);
46
+ }
47
+ }
48
+ }
49
+ exports.ChatHistory = ChatHistory;
@@ -0,0 +1,25 @@
1
+ import { HttpClient } from "../../http/http-client";
2
+ import { RequestOptions } from "../../http/transmit";
3
+ import { PagePromise } from "../../paging/page";
4
+ import { ChatHistory } from "./chat-history";
5
+ import { ChatMessage, ChatMessageListParams, SendChatMessageRequest } from "./chat-types";
6
+ /**
7
+ * Messages in a chat thread.
8
+ *
9
+ * @category chat
10
+ */
11
+ export declare class ChatThreadMessagesResource {
12
+ private readonly chat;
13
+ private readonly history;
14
+ constructor(chat: HttpClient, history: ChatHistory);
15
+ /**
16
+ * Lists a thread's messages, newest first; later pages go further back. Calls
17
+ * `GET v1/chat/threads/{threadId}/messages`.
18
+ */
19
+ list(threadId: string, params?: ChatMessageListParams, options?: RequestOptions): PagePromise<ChatMessage>;
20
+ /**
21
+ * Sends a text message. It carries a client id the server remembers, so a retried send is stored once. Calls
22
+ * `POST v1/chat/threads/{threadId}/messages`.
23
+ */
24
+ send(threadId: string, body: SendChatMessageRequest, options?: RequestOptions): Promise<ChatMessage>;
25
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatThreadMessagesResource = void 0;
4
+ const url_1 = require("../../http/url");
5
+ const cursor_pages_1 = require("../../paging/cursor-pages");
6
+ const chat_threads_resource_1 = require("./chat-threads-resource");
7
+ const CLIENT_ID_BYTES = 16;
8
+ const messagesPath = (threadId) => `${(0, chat_threads_resource_1.threadPath)(threadId)}/messages`;
9
+ const newClientId = () => Array.from(crypto.getRandomValues(new Uint8Array(CLIENT_ID_BYTES)), (byte) => byte.toString(16).padStart(2, "0"))
10
+ .join("");
11
+ /**
12
+ * Messages in a chat thread.
13
+ *
14
+ * @category chat
15
+ */
16
+ class ChatThreadMessagesResource {
17
+ constructor(chat, history) {
18
+ this.chat = chat;
19
+ this.history = history;
20
+ }
21
+ /**
22
+ * Lists a thread's messages, newest first; later pages go further back. Calls
23
+ * `GET v1/chat/threads/{threadId}/messages`.
24
+ */
25
+ list(threadId, params = {}, options) {
26
+ return (0, cursor_pages_1.cursorPages)(async (cursor) => {
27
+ const page = await this.chat.get(`${messagesPath(threadId)}${(0, url_1.toSearchQuery)({ ...params, cursor })}`, options);
28
+ this.history.seed(page.items.map((message) => message.sentAt));
29
+ return page;
30
+ });
31
+ }
32
+ /**
33
+ * Sends a text message. It carries a client id the server remembers, so a retried send is stored once. Calls
34
+ * `POST v1/chat/threads/{threadId}/messages`.
35
+ */
36
+ async send(threadId, body, options) {
37
+ const message = await this.chat.send({ method: "POST", path: messagesPath(threadId), body: { ...body, clientId: newClientId() }, idempotent: true }, options);
38
+ this.history.seed([message.sentAt]);
39
+ return message;
40
+ }
41
+ }
42
+ exports.ChatThreadMessagesResource = ChatThreadMessagesResource;
@@ -0,0 +1,44 @@
1
+ import { HttpClient } from "../../http/http-client";
2
+ import { RequestOptions } from "../../http/transmit";
3
+ import { OvokLogger } from "../../logging/ovok-logger";
4
+ import { SessionResource } from "../session/session-resource";
5
+ import { OpenSocket } from "./chat-connection";
6
+ import { ChatThreadMessagesResource } from "./chat-messages-resource";
7
+ import { ChatThreadsResource } from "./chat-threads-resource";
8
+ import { ChatEventHandler, ChatReadRequest, ChatStopListening } from "./chat-types";
9
+ /**
10
+ * Where the chat socket connects and logs.
11
+ *
12
+ * @category chat
13
+ */
14
+ export type ChatSettings = {
15
+ /** The API base URL; the socket connects to its origin. */
16
+ baseUrl: string;
17
+ /** Receives structured log entries. */
18
+ logger: OvokLogger;
19
+ };
20
+ /**
21
+ * Person-to-person chat between patients and their care team. Calls routes under `v1/chat`.
22
+ *
23
+ * @category chat
24
+ */
25
+ export declare class ChatResource {
26
+ /** The signed-in person's threads. */
27
+ readonly threads: ChatThreadsResource;
28
+ /** Messages in a thread. */
29
+ readonly messages: ChatThreadMessagesResource;
30
+ private readonly chat;
31
+ private readonly connection;
32
+ constructor(http: HttpClient, session: SessionResource, settings: ChatSettings, openSocket?: OpenSocket);
33
+ /** Marks a thread read by the signed-in person, now or at `readAt`. Calls `POST v1/chat/threads/{threadId}/read`. */
34
+ read(threadId: string, body?: ChatReadRequest, options?: RequestOptions): Promise<void>;
35
+ /**
36
+ * Calls `handler` for each new message, read receipt and new or changed thread of the signed-in person, live over
37
+ * the `/events` socket. One socket serves every `listen` of the client. After each reconnect it reads back what was
38
+ * missed and delivers it once, so a handler sees every message without polling. Listening ends on sign-out.
39
+ *
40
+ * @returns A function that stops this listener.
41
+ * @throws OvokPermissionError when chat is turned off or not allowed, or OvokConnectionError when it cannot connect.
42
+ */
43
+ listen(handler: ChatEventHandler): Promise<ChatStopListening>;
44
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatResource = void 0;
4
+ const socket_io_client_1 = require("socket.io-client");
5
+ const ovok_logger_1 = require("../../logging/ovok-logger");
6
+ const chat_connection_1 = require("./chat-connection");
7
+ const chat_history_1 = require("./chat-history");
8
+ const chat_messages_resource_1 = require("./chat-messages-resource");
9
+ const chat_threads_resource_1 = require("./chat-threads-resource");
10
+ const CHAT_PATH = "v1/chat";
11
+ /**
12
+ * Person-to-person chat between patients and their care team. Calls routes under `v1/chat`.
13
+ *
14
+ * @category chat
15
+ */
16
+ class ChatResource {
17
+ constructor(http, session, settings, openSocket = socket_io_client_1.io) {
18
+ const history = new chat_history_1.ChatHistory();
19
+ this.chat = http.under(CHAT_PATH);
20
+ this.threads = new chat_threads_resource_1.ChatThreadsResource(this.chat, history);
21
+ this.messages = new chat_messages_resource_1.ChatThreadMessagesResource(this.chat, history);
22
+ this.connection = new chat_connection_1.ChatConnection({
23
+ http,
24
+ session,
25
+ baseUrl: settings.baseUrl,
26
+ threads: this.threads,
27
+ messages: this.messages,
28
+ history,
29
+ logger: (0, ovok_logger_1.scopedLogger)(settings.logger, "chat"),
30
+ openSocket,
31
+ });
32
+ }
33
+ /** Marks a thread read by the signed-in person, now or at `readAt`. Calls `POST v1/chat/threads/{threadId}/read`. */
34
+ read(threadId, body = {}, options) {
35
+ return this.chat.post(`${(0, chat_threads_resource_1.threadPath)(threadId)}/read`, body, options);
36
+ }
37
+ /**
38
+ * Calls `handler` for each new message, read receipt and new or changed thread of the signed-in person, live over
39
+ * the `/events` socket. One socket serves every `listen` of the client. After each reconnect it reads back what was
40
+ * missed and delivers it once, so a handler sees every message without polling. Listening ends on sign-out.
41
+ *
42
+ * @returns A function that stops this listener.
43
+ * @throws OvokPermissionError when chat is turned off or not allowed, or OvokConnectionError when it cannot connect.
44
+ */
45
+ listen(handler) {
46
+ return this.connection.listen(handler);
47
+ }
48
+ }
49
+ exports.ChatResource = ChatResource;
@@ -0,0 +1,26 @@
1
+ import { HttpClient } from "../../http/http-client";
2
+ import { RequestOptions } from "../../http/transmit";
3
+ import { PagePromise } from "../../paging/page";
4
+ import { ChatHistory } from "./chat-history";
5
+ import { ChatThread, ChatThreadListParams, OpenChatThreadRequest } from "./chat-types";
6
+ export declare const threadPath: (threadId: string) => string;
7
+ /**
8
+ * The signed-in person's chat threads.
9
+ *
10
+ * @category chat
11
+ */
12
+ export declare class ChatThreadsResource {
13
+ private readonly chat;
14
+ private readonly history;
15
+ constructor(chat: HttpClient, history: ChatHistory);
16
+ /**
17
+ * Opens a thread about a patient, or answers the one these participants already have. Every participant must be
18
+ * allowed to read the patient. Calls `POST v1/chat/threads`.
19
+ */
20
+ open(body: OpenChatThreadRequest, options?: RequestOptions): Promise<ChatThread>;
21
+ /** Lists the signed-in person's threads, newest message first. Calls `GET v1/chat/threads`. */
22
+ list(params?: ChatThreadListParams, options?: RequestOptions): PagePromise<ChatThread>;
23
+ /** Reads one thread. Calls `GET v1/chat/threads/{threadId}`. */
24
+ retrieve(threadId: string, options?: RequestOptions): Promise<ChatThread>;
25
+ private seen;
26
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatThreadsResource = exports.threadPath = void 0;
4
+ const url_1 = require("../../http/url");
5
+ const cursor_pages_1 = require("../../paging/cursor-pages");
6
+ const chat_history_1 = require("./chat-history");
7
+ const THREADS_PATH = "threads";
8
+ const threadPath = (threadId) => `${THREADS_PATH}/${(0, url_1.pathSegment)(threadId)}`;
9
+ exports.threadPath = threadPath;
10
+ /**
11
+ * The signed-in person's chat threads.
12
+ *
13
+ * @category chat
14
+ */
15
+ class ChatThreadsResource {
16
+ constructor(chat, history) {
17
+ this.chat = chat;
18
+ this.history = history;
19
+ }
20
+ /**
21
+ * Opens a thread about a patient, or answers the one these participants already have. Every participant must be
22
+ * allowed to read the patient. Calls `POST v1/chat/threads`.
23
+ */
24
+ async open(body, options) {
25
+ return this.seen(await this.chat.post(THREADS_PATH, body, options));
26
+ }
27
+ /** Lists the signed-in person's threads, newest message first. Calls `GET v1/chat/threads`. */
28
+ list(params = {}, options) {
29
+ return (0, cursor_pages_1.cursorPages)(async (cursor) => {
30
+ const page = await this.chat.get(`${THREADS_PATH}${(0, url_1.toSearchQuery)({ ...params, cursor })}`, options);
31
+ this.history.seed(page.items.map(chat_history_1.activityOf));
32
+ return page;
33
+ });
34
+ }
35
+ /** Reads one thread. Calls `GET v1/chat/threads/{threadId}`. */
36
+ async retrieve(threadId, options) {
37
+ return this.seen(await this.chat.get((0, exports.threadPath)(threadId), options));
38
+ }
39
+ seen(thread) {
40
+ this.history.seed([(0, chat_history_1.activityOf)(thread)]);
41
+ return thread;
42
+ }
43
+ }
44
+ exports.ChatThreadsResource = ChatThreadsResource;
@@ -0,0 +1,157 @@
1
+ import type { OvokReference } from "../../auth/session";
2
+ /**
3
+ * Someone in a chat thread: a patient, practitioner or related person.
4
+ *
5
+ * @category chat
6
+ */
7
+ export type ChatParticipant = OvokReference;
8
+ /**
9
+ * One message in a chat thread.
10
+ *
11
+ * @category chat
12
+ */
13
+ export type ChatMessage = {
14
+ /** The message id. */
15
+ id: string;
16
+ /** The thread the message belongs to. */
17
+ threadId: string;
18
+ /** Who wrote it. */
19
+ sender: ChatParticipant;
20
+ /** The message text. */
21
+ text: string;
22
+ /** When the server accepted it, as an ISO date-time. */
23
+ sentAt: string;
24
+ /** The id of the message it replies to, or null. */
25
+ replyTo: string | null;
26
+ /** The id the sending client gave it, which makes a repeated send safe; null when none was given. */
27
+ clientId: string | null;
28
+ };
29
+ /**
30
+ * When one participant last read a thread.
31
+ *
32
+ * @category chat
33
+ */
34
+ export type ChatRead = {
35
+ /** The participant's reference. */
36
+ participant: string;
37
+ /** When they read it, as an ISO date-time. */
38
+ readAt: string;
39
+ };
40
+ /**
41
+ * A conversation about one patient between the patient and any of their care team.
42
+ *
43
+ * @category chat
44
+ */
45
+ export type ChatThread = {
46
+ /** The thread id. */
47
+ id: string;
48
+ /** The patient the thread is about. */
49
+ patient: ChatParticipant;
50
+ /** Everyone in the thread, the patient included. */
51
+ participants: ChatParticipant[];
52
+ /** The thread title, or null. */
53
+ title: string | null;
54
+ /** Whether new messages can be sent. */
55
+ status: "open" | "closed";
56
+ /** The newest message, or null when there is none yet. */
57
+ lastMessage: ChatMessage | null;
58
+ /** When the newest message was sent, or null when there is none yet. */
59
+ lastMessageAt: string | null;
60
+ /** Messages the signed-in person has not read. */
61
+ unreadCount: number;
62
+ /** When each participant last read the thread. */
63
+ reads: ChatRead[];
64
+ /** When the thread was opened, as an ISO date-time. */
65
+ createdAt: string;
66
+ };
67
+ /**
68
+ * Request body for opening a thread.
69
+ *
70
+ * @category chat
71
+ */
72
+ export type OpenChatThreadRequest = {
73
+ /** The patient the thread is about, as `Patient/<id>`. */
74
+ patient: string;
75
+ /** References of the other participants; the signed-in person is added. */
76
+ participants: string[];
77
+ /** An optional title. */
78
+ title?: string;
79
+ };
80
+ /**
81
+ * Filters for listing threads.
82
+ *
83
+ * @category chat
84
+ */
85
+ export type ChatThreadListParams = {
86
+ /** Only threads about this patient, as `Patient/<id>`. */
87
+ patient?: string;
88
+ /** Only threads changed at or after this ISO date-time. */
89
+ updatedSince?: string;
90
+ /** Threads per page. */
91
+ limit?: number;
92
+ };
93
+ /**
94
+ * Filters for listing messages.
95
+ *
96
+ * @category chat
97
+ */
98
+ export type ChatMessageListParams = {
99
+ /** Only messages sent after this ISO date-time. */
100
+ since?: string;
101
+ /** Messages per page. */
102
+ limit?: number;
103
+ };
104
+ /**
105
+ * Request body for sending a message.
106
+ *
107
+ * @category chat
108
+ */
109
+ export type SendChatMessageRequest = {
110
+ /** The message text. */
111
+ text: string;
112
+ /** The id of the message this one replies to. */
113
+ replyTo?: string;
114
+ };
115
+ /**
116
+ * Request body for marking a thread read.
117
+ *
118
+ * @category chat
119
+ */
120
+ export type ChatReadRequest = {
121
+ /** When the thread was read, as an ISO date-time; the server time when omitted. */
122
+ readAt?: string;
123
+ };
124
+ /**
125
+ * Something that happened in the signed-in person's threads: a message, a read receipt, or a thread that is new or
126
+ * changed.
127
+ *
128
+ * @category chat
129
+ */
130
+ export type ChatEvent = {
131
+ /** A new message, the signed-in person's own included. */
132
+ type: "message";
133
+ /** The message. */
134
+ message: ChatMessage;
135
+ } | ({
136
+ /** A participant read a thread. */
137
+ type: "read";
138
+ /** The thread that was read. */
139
+ threadId: string;
140
+ } & ChatRead) | {
141
+ /** A thread is new or changed. */
142
+ type: "thread";
143
+ /** The thread as it is now. */
144
+ thread: ChatThread;
145
+ };
146
+ /**
147
+ * Receives chat events.
148
+ *
149
+ * @category chat
150
+ */
151
+ export type ChatEventHandler = (event: ChatEvent) => void;
152
+ /**
153
+ * Stops one `listen`; the socket closes once no listener is left.
154
+ *
155
+ * @category chat
156
+ */
157
+ export type ChatStopListening = () => Promise<void>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,49 @@
1
+ import { HttpClient } from "../../http/http-client";
2
+ import { RequestOptions } from "../../http/transmit";
3
+ import { PagePromise } from "../../paging/page";
4
+ /**
5
+ * Field conditions every listed document meets, by field (dots reach into relations, e.g. `contentType.slug`) and
6
+ * then by Payload operator (`equals`, `not_equals`, `in`, `exists`, …).
7
+ *
8
+ * @category cms
9
+ */
10
+ export type CmsWhere = Record<string, Record<string, string | number | boolean>>;
11
+ /**
12
+ * What a listing of documents being authored returns. `limit` is the page size; `depth` how far relations are filled in.
13
+ *
14
+ * @category cms
15
+ */
16
+ export type CmsAuthoringListParams = {
17
+ /** Conditions every document meets. */
18
+ where?: CmsWhere;
19
+ /** Page number to fetch. */
20
+ page?: number;
21
+ /** Documents per page. */
22
+ limit?: number;
23
+ /** Field to sort by; prefix with `-` for descending. */
24
+ sort?: string;
25
+ /** How deep to fill in related documents; 0 answers their ids. */
26
+ depth?: number;
27
+ /** The CMS locale to read localized fields in, such as `de`. */
28
+ locale?: string;
29
+ };
30
+ /**
31
+ * The project's own CMS documents in every status, drafts included, to read and write as the signed-in user. Calls
32
+ * routes under `v1/content`, which act on the caller's own project only.
33
+ *
34
+ * @category cms
35
+ */
36
+ export declare class CmsAuthoringResource {
37
+ private readonly http;
38
+ constructor(http: HttpClient);
39
+ /** Lists a collection's documents, page by page. Calls `GET v1/content/{collection}`. */
40
+ list<T extends object>(collection: string, params?: CmsAuthoringListParams, options?: RequestOptions): PagePromise<T>;
41
+ /** Reads one document by id. Calls `GET v1/content/{collection}/{id}`. */
42
+ retrieve<T extends object>(collection: string, id: number | string, options?: RequestOptions): Promise<T>;
43
+ /** Creates a document and answers it. Calls `POST v1/content/{collection}`. */
44
+ create<T extends object>(collection: string, document: object, options?: RequestOptions): Promise<T>;
45
+ /** Changes the fields given and answers the document; a field sent replaces its value whole. Calls `PATCH v1/content/{collection}/{id}`. */
46
+ update<T extends object>(collection: string, id: number | string, fields: object, options?: RequestOptions): Promise<T>;
47
+ /** Deletes a document. Calls `DELETE v1/content/{collection}/{id}`. */
48
+ delete(collection: string, id: number | string, options?: RequestOptions): Promise<void>;
49
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CmsAuthoringResource = void 0;
4
+ const query_string_1 = require("../../../client/query-string");
5
+ const url_1 = require("../../http/url");
6
+ const payload_pages_1 = require("./payload-pages");
7
+ const CONTENT_PATH = "v1/content";
8
+ const collectionPath = (collection) => `${CONTENT_PATH}/${(0, url_1.pathSegment)(collection)}`;
9
+ const documentPath = (collection, id) => `${collectionPath(collection)}/${(0, url_1.pathSegment)(String(id))}`;
10
+ const whereQuery = (where = {}) => Object.fromEntries(Object.entries(where).flatMap(([field, conditions]) => Object.entries(conditions).map(([operator, value]) => [`where[${field}][${operator}]`, value])));
11
+ /**
12
+ * The project's own CMS documents in every status, drafts included, to read and write as the signed-in user. Calls
13
+ * routes under `v1/content`, which act on the caller's own project only.
14
+ *
15
+ * @category cms
16
+ */
17
+ class CmsAuthoringResource {
18
+ constructor(http) {
19
+ this.http = http;
20
+ }
21
+ /** Lists a collection's documents, page by page. Calls `GET v1/content/{collection}`. */
22
+ list(collection, params = {}, options) {
23
+ const { where, ...rest } = params;
24
+ const query = (page) => (0, query_string_1.toQueryString)({ ...whereQuery(where), ...rest, page });
25
+ return (0, payload_pages_1.payloadPages)((page) => this.http.get(`${collectionPath(collection)}${query(page)}`, options), params.page);
26
+ }
27
+ /** Reads one document by id. Calls `GET v1/content/{collection}/{id}`. */
28
+ retrieve(collection, id, options) {
29
+ return this.http.get(documentPath(collection, id), options);
30
+ }
31
+ /** Creates a document and answers it. Calls `POST v1/content/{collection}`. */
32
+ async create(collection, document, options) {
33
+ const { doc } = await this.http.post(collectionPath(collection), document, options);
34
+ return doc;
35
+ }
36
+ /** Changes the fields given and answers the document; a field sent replaces its value whole. Calls `PATCH v1/content/{collection}/{id}`. */
37
+ async update(collection, id, fields, options) {
38
+ const { doc } = await this.http.patch(documentPath(collection, id), fields, options);
39
+ return doc;
40
+ }
41
+ /** Deletes a document. Calls `DELETE v1/content/{collection}/{id}`. */
42
+ async delete(collection, id, options) {
43
+ await this.http.delete(documentPath(collection, id), options);
44
+ }
45
+ }
46
+ exports.CmsAuthoringResource = CmsAuthoringResource;
@@ -1,4 +1,4 @@
1
- import type { OvokCmsPage } from "../../../client/cms/types";
1
+ import type { OvokCmsContentItem, OvokCmsPage } from "../../../client/cms/types";
2
2
  import { HttpClient } from "../../http/http-client";
3
3
  import { RequestOptions } from "../../http/transmit";
4
4
  /**
@@ -30,5 +30,6 @@ export declare class CmsDelivery {
30
30
  constructor(http: HttpClient, tenantCode: string);
31
31
  listPage<T extends object>(collection: string, params: CmsListParams, options?: RequestOptions): Promise<OvokCmsPage<T>>;
32
32
  retrieve<T extends object>(collection: string, slug: string, params: CmsReadParams, options?: RequestOptions): Promise<T>;
33
+ contentItems<T extends object>(contentTypeSlug: string, options?: RequestOptions): Promise<OvokCmsPage<OvokCmsContentItem<T>>>;
33
34
  private queryFor;
34
35
  }
@@ -5,7 +5,8 @@ const locale_1 = require("../../../client/cms/locale");
5
5
  const query_string_1 = require("../../../client/query-string");
6
6
  const ovok_errors_1 = require("../../errors/ovok-errors");
7
7
  const url_1 = require("../../http/url");
8
- const COLLECTIONS_PATH = "v1/public/cms/collections";
8
+ const CMS_PATH = "v1/public/cms";
9
+ const COLLECTIONS_PATH = `${CMS_PATH}/collections`;
9
10
  const itemsPath = (collection) => `${COLLECTIONS_PATH}/${(0, url_1.pathSegment)(collection)}/items`;
10
11
  /** Published documents, always read as the client's tenant: signed out, the CMS knows it only from `?tenant=`. */
11
12
  class CmsDelivery {
@@ -22,6 +23,13 @@ class CmsDelivery {
22
23
  }
23
24
  return this.http.get(`${itemsPath(collection)}/${(0, url_1.pathSegment)(slug)}${this.queryFor(params)}`, options);
24
25
  }
26
+ async contentItems(contentTypeSlug, options) {
27
+ if (contentTypeSlug === "") {
28
+ throw new ovok_errors_1.OvokValidationError((0, ovok_errors_1.detailsFor)("A content type read needs the type's slug."));
29
+ }
30
+ const query = (0, query_string_1.toQueryString)({ tenant: this.tenantCode });
31
+ return this.http.get(`${CMS_PATH}/${(0, url_1.pathSegment)(contentTypeSlug)}/items${query}`, options);
32
+ }
25
33
  // An empty locale or sort counts as absent.
26
34
  queryFor({ locale, page, limit, sort }) {
27
35
  return (0, query_string_1.toQueryString)({
@@ -1,13 +1,15 @@
1
- import type { OvokCmsDocument, OvokTranslations } from "../../../client/cms/types";
1
+ import type { OvokCmsContentItem, OvokCmsDocument, OvokCmsPage, OvokTranslations } from "../../../client/cms/types";
2
2
  import { HttpClient } from "../../http/http-client";
3
3
  import { RequestOptions } from "../../http/transmit";
4
+ import { CmsAuthoringResource } from "./cms-authoring-resource";
4
5
  import { CmsReadParams } from "./cms-delivery";
5
6
  import { CmsDocumentsResource } from "./cms-documents-resource";
6
7
  import { ReleaseNotesResource } from "./release-notes-resource";
7
8
  /** 25,000 documents: far beyond any real collection, so reaching it means the CMS never ends its pages. */
8
9
  export declare const MAX_TRANSLATION_PAGES = 500;
9
10
  /**
10
- * Published CMS content: documents, legal pages, release notes and translations. Calls routes under `v1/public/cms`.
11
+ * CMS content. Published documents, legal pages, release notes, translations and content type items come from routes
12
+ * under `v1/public/cms`; `authoring` reads and writes every status under `v1/content`.
11
13
  *
12
14
  * @category cms
13
15
  */
@@ -16,10 +18,19 @@ export declare class CmsResource {
16
18
  readonly documents: CmsDocumentsResource;
17
19
  /** Reads release notes. */
18
20
  readonly releaseNotes: ReleaseNotesResource;
21
+ /** Reads and writes the project's own documents in every status. */
22
+ readonly authoring: CmsAuthoringResource;
19
23
  private readonly delivery;
20
24
  constructor(http: HttpClient, tenantCode: string);
21
25
  /** "terms-and-conditions", "data-privacy", …: readable before sign-in. */
22
26
  legalPage(slug: string, params?: CmsReadParams, options?: RequestOptions): Promise<OvokCmsDocument>;
27
+ /**
28
+ * The published items of a content type defined in the Console, at most 100, in the CMS's order. Needs a signed-in
29
+ * user of the tenant: this route is never open.
30
+ *
31
+ * @throws OvokValidationError for an empty slug.
32
+ */
33
+ contentItems<T extends object = Record<string, unknown>>(contentTypeSlug: string, options?: RequestOptions): Promise<OvokCmsPage<OvokCmsContentItem<T>>>;
23
34
  /**
24
35
  * The `translations` collection as one tree, readable before sign-in; nothing is kept on the device.
25
36
  * Reads every page of the collection.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CmsResource = exports.MAX_TRANSLATION_PAGES = void 0;
4
4
  const ovok_errors_1 = require("../../errors/ovok-errors");
5
+ const cms_authoring_resource_1 = require("./cms-authoring-resource");
5
6
  const cms_delivery_1 = require("./cms-delivery");
6
7
  const cms_documents_resource_1 = require("./cms-documents-resource");
7
8
  const release_notes_resource_1 = require("./release-notes-resource");
@@ -14,7 +15,8 @@ const LARGEST_PAGE_SIZE = 50;
14
15
  exports.MAX_TRANSLATION_PAGES = 500;
15
16
  const TRANSLATION_PAGE_LIMIT_CODE = "cms_translations_page_limit";
16
17
  /**
17
- * Published CMS content: documents, legal pages, release notes and translations. Calls routes under `v1/public/cms`.
18
+ * CMS content. Published documents, legal pages, release notes, translations and content type items come from routes
19
+ * under `v1/public/cms`; `authoring` reads and writes every status under `v1/content`.
18
20
  *
19
21
  * @category cms
20
22
  */
@@ -23,11 +25,21 @@ class CmsResource {
23
25
  this.delivery = new cms_delivery_1.CmsDelivery(http, tenantCode);
24
26
  this.documents = new cms_documents_resource_1.CmsDocumentsResource(this.delivery);
25
27
  this.releaseNotes = new release_notes_resource_1.ReleaseNotesResource(this.documents);
28
+ this.authoring = new cms_authoring_resource_1.CmsAuthoringResource(http);
26
29
  }
27
30
  /** "terms-and-conditions", "data-privacy", …: readable before sign-in. */
28
31
  legalPage(slug, params = {}, options) {
29
32
  return this.documents.retrieve(LEGAL_PAGES, slug, params, options);
30
33
  }
34
+ /**
35
+ * The published items of a content type defined in the Console, at most 100, in the CMS's order. Needs a signed-in
36
+ * user of the tenant: this route is never open.
37
+ *
38
+ * @throws OvokValidationError for an empty slug.
39
+ */
40
+ contentItems(contentTypeSlug, options) {
41
+ return this.delivery.contentItems(contentTypeSlug, options);
42
+ }
31
43
  /**
32
44
  * The `translations` collection as one tree, readable before sign-in; nothing is kept on the device.
33
45
  * Reads every page of the collection.
@@ -35,7 +35,7 @@ export declare class DocumentsResource {
35
35
  /** Lists documents. Calls `GET document`. */
36
36
  list(params?: OvokDocumentSearchQuery, options?: RequestOptions): Promise<OvokDocumentSearchResponse>;
37
37
  /** Registers a document upload. Calls `POST document`. */
38
- createUpload(body: OvokDocumentUploadRequest, options?: RequestOptions): Promise<OvokDocumentFile>;
38
+ createUpload({ isPublic, ...body }: OvokDocumentUploadRequest, options?: RequestOptions): Promise<OvokDocumentFile>;
39
39
  /** Replaces the file of a document. Calls `POST document/{documentId}`. */
40
40
  replaceUpload(documentId: string, body: OvokDocumentReplacement, options?: RequestOptions): Promise<OvokDocumentFile>;
41
41
  /** Updates a document's metadata. Calls `PATCH document/{documentId}`. */
@@ -21,8 +21,10 @@ class DocumentsResource {
21
21
  return this.http.get(`${DOCUMENT_PATH}${(0, query_string_1.toQueryString)(params)}`, options);
22
22
  }
23
23
  /** Registers a document upload. Calls `POST document`. */
24
- createUpload(body, options) {
25
- return this.http.post(DOCUMENT_PATH, body, options);
24
+ createUpload({ isPublic, ...body }, options) {
25
+ // This route reads isPublic as the text "true" or "false" and refuses a JSON boolean.
26
+ const visibility = isPublic === undefined ? {} : { isPublic: String(isPublic) };
27
+ return this.http.post(DOCUMENT_PATH, { ...body, ...visibility }, options);
26
28
  }
27
29
  /** Replaces the file of a document. Calls `POST document/{documentId}`. */
28
30
  replaceUpload(documentId, body, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ovok/core",
3
- "version": "0.4.59-dev.564+6c0147c",
3
+ "version": "0.4.59-dev.566+7e4647b",
4
4
  "private": false,
5
5
  "main": "dist/next/index.js",
6
6
  "types": "dist/next/index.d.ts",
@@ -101,6 +101,9 @@
101
101
  "typescript": "^5.3.3",
102
102
  "typescript-eslint": "^8.15.0"
103
103
  },
104
+ "dependencies": {
105
+ "socket.io-client": "^4.8.3"
106
+ },
104
107
  "peerDependencies": {
105
108
  "@medplum/fhirtypes": ">=3.2.22",
106
109
  "react": "*"