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

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.
@@ -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.566+7e4647b",
29
+ version: "0.4.59-dev.567+06fe40c",
30
30
  },
31
31
  fhirVersion: "4.0.1",
32
32
  format: ["json"],
@@ -52,7 +52,7 @@ export type { DeletedDocument, DocumentDownloadParams } from "./resources/docume
52
52
  export type { BotInput, BotOutput } from "./resources/bots/bots-resource";
53
53
  export type { PushDevice, PushDeviceList, PushPlatform, RegisterPushDeviceRequest, } from "./resources/push/push-devices-resource";
54
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";
55
+ export type { ChatAttachment, ChatAttachmentContentType, ChatAttachmentLink, ChatAttachmentUploadRequest, ChatEvent, ChatEventHandler, ChatMessage, ChatMessageListParams, ChatParticipant, ChatRead, ChatReadRequest, ChatStopListening, ChatThread, ChatThreadListParams, OpenChatThreadRequest, SendChatMessageRequest, } from "./resources/chat/chat-types";
56
56
  export type { NotificationsRule, NotificationsRuleResponse } from "./resources/omnichannel-alerts/notifications-rules-resource";
57
57
  export type { NotificationsPreviewAlert, NotificationsPreviewNotify, NotificationsPreviewRecipient, NotificationsPreviewRequest, NotificationsPreviewResponse, OmnichannelAlertEvent, } from "./resources/omnichannel-alerts/omnichannel-alerts-resource";
58
58
  export type * from "./resources/slim/slim-queries";
@@ -61,6 +61,7 @@ export type { AiResource } from "./resources/ai/ai-resource";
61
61
  export type { AuthResource } from "./resources/auth-resource";
62
62
  export type { BotsResource } from "./resources/bots/bots-resource";
63
63
  export type { ChatResource, ChatSettings } from "./resources/chat/chat-resource";
64
+ export type { ChatAttachmentsResource } from "./resources/chat/chat-attachments-resource";
64
65
  export type { ChatThreadMessagesResource } from "./resources/chat/chat-messages-resource";
65
66
  export type { ChatThreadsResource } from "./resources/chat/chat-threads-resource";
66
67
  export type { CmsAuthoringResource } from "./resources/cms/cms-authoring-resource";
@@ -0,0 +1,28 @@
1
+ import { OvokFetch } from "../../config/ovok-config";
2
+ import { HttpClient } from "../../http/http-client";
3
+ import { RequestOptions } from "../../http/transmit";
4
+ import { ChatAttachment, ChatAttachmentLink, ChatAttachmentUploadRequest } from "./chat-types";
5
+ /**
6
+ * Files the signed-in person uploads to send in their chat threads.
7
+ *
8
+ * @category chat
9
+ */
10
+ export declare class ChatAttachmentsResource {
11
+ private readonly chat;
12
+ private readonly fetchFile;
13
+ constructor(chat: HttpClient, fetchFile: OvokFetch);
14
+ /**
15
+ * Uploads a PDF, PNG, JPEG or WebP of up to 10 MB, kept private. Send it with `messages.send(threadId, { text,
16
+ * attachments: [attachment.id] })`, in as many threads as you like. Calls `POST v1/chat/attachments`, then stores the
17
+ * file where the server says.
18
+ *
19
+ * @throws OvokServiceError when the store refuses the file, for example because it is larger than 10 MB.
20
+ */
21
+ upload(request: ChatAttachmentUploadRequest, options?: RequestOptions): Promise<ChatAttachment>;
22
+ /**
23
+ * A link that downloads one of the signed-in person's own uploads for the next hour. Calls
24
+ * `GET v1/chat/attachments/{attachmentId}`.
25
+ */
26
+ link(attachmentId: string, options?: RequestOptions): Promise<ChatAttachmentLink>;
27
+ private store;
28
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatAttachmentsResource = void 0;
4
+ const ovok_errors_1 = require("../../errors/ovok-errors");
5
+ const url_1 = require("../../http/url");
6
+ const ATTACHMENTS_PATH = "attachments";
7
+ /**
8
+ * Files the signed-in person uploads to send in their chat threads.
9
+ *
10
+ * @category chat
11
+ */
12
+ class ChatAttachmentsResource {
13
+ constructor(chat, fetchFile) {
14
+ this.chat = chat;
15
+ this.fetchFile = fetchFile;
16
+ }
17
+ /**
18
+ * Uploads a PDF, PNG, JPEG or WebP of up to 10 MB, kept private. Send it with `messages.send(threadId, { text,
19
+ * attachments: [attachment.id] })`, in as many threads as you like. Calls `POST v1/chat/attachments`, then stores the
20
+ * file where the server says.
21
+ *
22
+ * @throws OvokServiceError when the store refuses the file, for example because it is larger than 10 MB.
23
+ */
24
+ async upload(request, options) {
25
+ const { file, fileName, contentType } = request;
26
+ const { upload, ...attachment } = await this.chat.post(ATTACHMENTS_PATH, { fileName, contentType }, options);
27
+ const form = new FormData();
28
+ for (const [name, value] of Object.entries(upload.fields)) {
29
+ form.append(name, value);
30
+ }
31
+ form.append("file", file, fileName);
32
+ await this.store(upload.url, form, options);
33
+ return attachment;
34
+ }
35
+ /**
36
+ * A link that downloads one of the signed-in person's own uploads for the next hour. Calls
37
+ * `GET v1/chat/attachments/{attachmentId}`.
38
+ */
39
+ link(attachmentId, options) {
40
+ return this.chat.get(`${ATTACHMENTS_PATH}/${(0, url_1.pathSegment)(attachmentId)}`, options);
41
+ }
42
+ async store(url, form, options) {
43
+ var _a;
44
+ const stored = await this.fetchFile(url, { method: "POST", body: form, signal: options === null || options === void 0 ? void 0 : options.signal }).catch((error) => {
45
+ throw new ovok_errors_1.OvokConnectionError((0, ovok_errors_1.detailsFor)("Could not reach the file store."), error);
46
+ });
47
+ await ((_a = stored.body) === null || _a === void 0 ? void 0 : _a.cancel().catch(() => undefined));
48
+ if (!stored.ok) {
49
+ throw new ovok_errors_1.OvokServiceError({ ...(0, ovok_errors_1.detailsFor)(`The file store refused the file (${stored.status}).`), status: stored.status });
50
+ }
51
+ }
52
+ }
53
+ exports.ChatAttachmentsResource = ChatAttachmentsResource;
@@ -2,7 +2,7 @@ import { HttpClient } from "../../http/http-client";
2
2
  import { RequestOptions } from "../../http/transmit";
3
3
  import { PagePromise } from "../../paging/page";
4
4
  import { ChatHistory } from "./chat-history";
5
- import { ChatMessage, ChatMessageListParams, SendChatMessageRequest } from "./chat-types";
5
+ import { ChatAttachmentLink, ChatMessage, ChatMessageListParams, SendChatMessageRequest } from "./chat-types";
6
6
  /**
7
7
  * Messages in a chat thread.
8
8
  *
@@ -18,8 +18,13 @@ export declare class ChatThreadMessagesResource {
18
18
  */
19
19
  list(threadId: string, params?: ChatMessageListParams, options?: RequestOptions): PagePromise<ChatMessage>;
20
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`.
21
+ * Sends a message, with any of the signed-in person's own uploads. It carries a client id the server remembers, so a
22
+ * retried send is stored once. Calls `POST v1/chat/threads/{threadId}/messages`.
23
23
  */
24
24
  send(threadId: string, body: SendChatMessageRequest, options?: RequestOptions): Promise<ChatMessage>;
25
+ /**
26
+ * A link that downloads a file sent with a message, for the next hour. Calls
27
+ * `GET v1/chat/threads/{threadId}/messages/{messageId}/attachments/{attachmentId}`.
28
+ */
29
+ attachmentLink(threadId: string, messageId: string, attachmentId: string, options?: RequestOptions): Promise<ChatAttachmentLink>;
25
30
  }
@@ -30,13 +30,26 @@ class ChatThreadMessagesResource {
30
30
  });
31
31
  }
32
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`.
33
+ * Sends a message, with any of the signed-in person's own uploads. It carries a client id the server remembers, so a
34
+ * retried send is stored once. Calls `POST v1/chat/threads/{threadId}/messages`.
35
35
  */
36
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);
37
+ var _a;
38
+ const message = await this.chat.send({
39
+ method: "POST",
40
+ path: messagesPath(threadId),
41
+ body: { ...body, clientId: (_a = body.clientId) !== null && _a !== void 0 ? _a : newClientId() },
42
+ idempotent: true,
43
+ }, options);
38
44
  this.history.seed([message.sentAt]);
39
45
  return message;
40
46
  }
47
+ /**
48
+ * A link that downloads a file sent with a message, for the next hour. Calls
49
+ * `GET v1/chat/threads/{threadId}/messages/{messageId}/attachments/{attachmentId}`.
50
+ */
51
+ attachmentLink(threadId, messageId, attachmentId, options) {
52
+ return this.chat.get(`${messagesPath(threadId)}/${(0, url_1.pathSegment)(messageId)}/attachments/${(0, url_1.pathSegment)(attachmentId)}`, options);
53
+ }
41
54
  }
42
55
  exports.ChatThreadMessagesResource = ChatThreadMessagesResource;
@@ -1,7 +1,9 @@
1
+ import { OvokFetch } from "../../config/ovok-config";
1
2
  import { HttpClient } from "../../http/http-client";
2
3
  import { RequestOptions } from "../../http/transmit";
3
4
  import { OvokLogger } from "../../logging/ovok-logger";
4
5
  import { SessionResource } from "../session/session-resource";
6
+ import { ChatAttachmentsResource } from "./chat-attachments-resource";
5
7
  import { OpenSocket } from "./chat-connection";
6
8
  import { ChatThreadMessagesResource } from "./chat-messages-resource";
7
9
  import { ChatThreadsResource } from "./chat-threads-resource";
@@ -16,6 +18,8 @@ export type ChatSettings = {
16
18
  baseUrl: string;
17
19
  /** Receives structured log entries. */
18
20
  logger: OvokLogger;
21
+ /** Stores uploaded files where the server says. */
22
+ fetch: OvokFetch;
19
23
  };
20
24
  /**
21
25
  * Person-to-person chat between patients and their care team. Calls routes under `v1/chat`.
@@ -27,6 +31,8 @@ export declare class ChatResource {
27
31
  readonly threads: ChatThreadsResource;
28
32
  /** Messages in a thread. */
29
33
  readonly messages: ChatThreadMessagesResource;
34
+ /** Files to send in threads. */
35
+ readonly attachments: ChatAttachmentsResource;
30
36
  private readonly chat;
31
37
  private readonly connection;
32
38
  constructor(http: HttpClient, session: SessionResource, settings: ChatSettings, openSocket?: OpenSocket);
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChatResource = void 0;
4
4
  const socket_io_client_1 = require("socket.io-client");
5
5
  const ovok_logger_1 = require("../../logging/ovok-logger");
6
+ const chat_attachments_resource_1 = require("./chat-attachments-resource");
6
7
  const chat_connection_1 = require("./chat-connection");
7
8
  const chat_history_1 = require("./chat-history");
8
9
  const chat_messages_resource_1 = require("./chat-messages-resource");
@@ -19,6 +20,7 @@ class ChatResource {
19
20
  this.chat = http.under(CHAT_PATH);
20
21
  this.threads = new chat_threads_resource_1.ChatThreadsResource(this.chat, history);
21
22
  this.messages = new chat_messages_resource_1.ChatThreadMessagesResource(this.chat, history);
23
+ this.attachments = new chat_attachments_resource_1.ChatAttachmentsResource(this.chat, settings.fetch);
22
24
  this.connection = new chat_connection_1.ChatConnection({
23
25
  http,
24
26
  session,
@@ -19,6 +19,8 @@ export type ChatMessage = {
19
19
  sender: ChatParticipant;
20
20
  /** The message text. */
21
21
  text: string;
22
+ /** Files sent with the text. */
23
+ attachments: ChatAttachment[];
22
24
  /** When the server accepted it, as an ISO date-time. */
23
25
  sentAt: string;
24
26
  /** The id of the message it replies to, or null. */
@@ -26,6 +28,49 @@ export type ChatMessage = {
26
28
  /** The id the sending client gave it, which makes a repeated send safe; null when none was given. */
27
29
  clientId: string | null;
28
30
  };
31
+ /**
32
+ * A file sent with a chat message.
33
+ *
34
+ * @category chat
35
+ */
36
+ export type ChatAttachment = {
37
+ /** The attachment id. */
38
+ id: string;
39
+ /** The file's name. */
40
+ title: string;
41
+ /** The file's MIME type. */
42
+ contentType: string;
43
+ };
44
+ /**
45
+ * A link that downloads an attachment without a bearer, until it expires.
46
+ *
47
+ * @category chat
48
+ */
49
+ export type ChatAttachmentLink = {
50
+ /** Downloads the file; fits a browser tab, a download or a PDF viewer. */
51
+ url: string;
52
+ /** When the link stops working, as an ISO date-time. */
53
+ expiresAt: string;
54
+ };
55
+ /**
56
+ * The file types chat accepts.
57
+ *
58
+ * @category chat
59
+ */
60
+ export type ChatAttachmentContentType = "application/pdf" | "image/png" | "image/jpeg" | "image/webp";
61
+ /**
62
+ * A file to upload for chat.
63
+ *
64
+ * @category chat
65
+ */
66
+ export type ChatAttachmentUploadRequest = {
67
+ /** The file, at most 10 MB. */
68
+ file: Blob;
69
+ /** The file's name, as readers see it. */
70
+ fileName: string;
71
+ /** The file's type. */
72
+ contentType: ChatAttachmentContentType;
73
+ };
29
74
  /**
30
75
  * When one participant last read a thread.
31
76
  *
@@ -109,8 +154,12 @@ export type ChatMessageListParams = {
109
154
  export type SendChatMessageRequest = {
110
155
  /** The message text. */
111
156
  text: string;
157
+ /** Ids of the signed-in person's own uploads to send with the text, at most 5. */
158
+ attachments?: string[];
112
159
  /** The id of the message this one replies to. */
113
160
  replyTo?: string;
161
+ /** Your id for the message: the same id in the same thread again is the same message. Generated when omitted. */
162
+ clientId?: string;
114
163
  };
115
164
  /**
116
165
  * Request body for marking a thread read.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ovok/core",
3
- "version": "0.4.59-dev.566+7e4647b",
3
+ "version": "0.4.59-dev.567+06fe40c",
4
4
  "private": false,
5
5
  "main": "dist/next/index.js",
6
6
  "types": "dist/next/index.d.ts",