@doist/comms-sdk 3.0.2 → 3.2.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.
@@ -1,7 +1,9 @@
1
- import { ENDPOINT_ATTACHMENTS } from '../consts/endpoints.js';
1
+ import { z } from 'zod';
2
+ import { ENDPOINT_ATTACHMENTS, ENDPOINT_FILES } from '../consts/endpoints.js';
3
+ import { request } from '../transport/http-client.js';
2
4
  import { AttachmentSchema } from '../types/entities.js';
3
5
  import { uploadMultipartFile } from '../utils/multipart-upload.js';
4
- import { isValidUuidV7Base58, resolveCreateId, UuidV7Error } from '../utils/uuidv7.js';
6
+ import { isValidUuidV7Base58, resolveCreateId, resolveReferenceId, UuidV7Error, } from '../utils/uuidv7.js';
5
7
  import { BaseClient } from './base-client.js';
6
8
  /**
7
9
  * Resolve the `attachment_id`: validate a caller-supplied value (throwing an
@@ -15,14 +17,40 @@ function resolveAttachmentId(attachmentId) {
15
17
  }
16
18
  return resolveCreateId(attachmentId);
17
19
  }
20
+ export const IMAGE_READ_MIME_TYPES = ['image/jpeg', 'image/png', 'image/webp'];
21
+ const IMAGE_READ_MAX_BYTES = 5 * 1024 * 1024;
22
+ export const ImageReadResultSchema = z.object({
23
+ mimeType: z.enum(IMAGE_READ_MIME_TYPES),
24
+ // The API allows 5 MiB of image bytes. Base64 encodes each three-byte group
25
+ // as four characters, including padding for the last group.
26
+ dataBase64: z
27
+ .string()
28
+ .min(1)
29
+ .max(4 * Math.ceil(IMAGE_READ_MAX_BYTES / 3))
30
+ .base64(),
31
+ byteLength: z.number().int().positive().max(IMAGE_READ_MAX_BYTES),
32
+ });
18
33
  /**
19
- * Client for uploading file attachments to Comms.
34
+ * Client for uploading attachments and reading thread images.
20
35
  *
21
36
  * Attachments are uploaded independently, then referenced by passing the returned
22
37
  * {@link Attachment} into the `attachments` array of `comments.createComment`,
23
38
  * `conversationMessages.createMessage`, and similar calls.
24
39
  */
25
40
  export class AttachmentsClient extends BaseClient {
41
+ /** Read one thread image under the caller's content scope. */
42
+ async readImage(uploadId, threadId) {
43
+ const id = resolveReferenceId(uploadId, 'uploadId');
44
+ const checkedThreadId = resolveReferenceId(threadId, 'threadId');
45
+ const response = await request({
46
+ httpMethod: 'GET',
47
+ baseUri: this.getBaseUri(),
48
+ relativePath: `${ENDPOINT_FILES}/image/${checkedThreadId}/${id}`,
49
+ apiToken: this.apiToken,
50
+ customFetch: this.customFetch,
51
+ });
52
+ return ImageReadResultSchema.parse(response.data);
53
+ }
26
54
  /**
27
55
  * Uploads a file and returns the created {@link Attachment}.
28
56
  *
@@ -27,4 +27,5 @@ export const ENDPOINT_REACTIONS = 'reactions';
27
27
  export const ENDPOINT_SEARCH = 'search';
28
28
  export const ENDPOINT_CONVERSATION_MESSAGES = 'conversation_messages';
29
29
  export const ENDPOINT_ATTACHMENTS = 'attachments';
30
+ export const ENDPOINT_FILES = 'files';
30
31
  export const ENDPOINT_HOOKS = 'hooks';
package/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './authentication.js';
2
2
  export * from './migration.js';
3
- export { AttachmentsClient } from './clients/attachments-client.js';
3
+ export { AttachmentsClient, IMAGE_READ_MIME_TYPES, ImageReadResultSchema, } from './clients/attachments-client.js';
4
4
  export { ChannelsClient } from './clients/channels-client.js';
5
5
  export { CommentsClient } from './clients/comments-client.js';
6
6
  export { ConversationMessagesClient } from './clients/conversation-messages-client.js';
@@ -1,14 +1,29 @@
1
+ import { z } from 'zod';
1
2
  import { type Attachment } from '../types/entities.js';
2
3
  import type { UploadAttachmentArgs } from '../types/requests.js';
3
4
  import { BaseClient } from './base-client.js';
5
+ export declare const IMAGE_READ_MIME_TYPES: readonly ["image/jpeg", "image/png", "image/webp"];
6
+ export type ImageReadMimeType = (typeof IMAGE_READ_MIME_TYPES)[number];
7
+ export declare const ImageReadResultSchema: z.ZodObject<{
8
+ mimeType: z.ZodEnum<{
9
+ "image/png": "image/png";
10
+ "image/jpeg": "image/jpeg";
11
+ "image/webp": "image/webp";
12
+ }>;
13
+ dataBase64: z.ZodString;
14
+ byteLength: z.ZodNumber;
15
+ }, z.core.$strip>;
16
+ export type ImageReadResult = z.infer<typeof ImageReadResultSchema>;
4
17
  /**
5
- * Client for uploading file attachments to Comms.
18
+ * Client for uploading attachments and reading thread images.
6
19
  *
7
20
  * Attachments are uploaded independently, then referenced by passing the returned
8
21
  * {@link Attachment} into the `attachments` array of `comments.createComment`,
9
22
  * `conversationMessages.createMessage`, and similar calls.
10
23
  */
11
24
  export declare class AttachmentsClient extends BaseClient {
25
+ /** Read one thread image under the caller's content scope. */
26
+ readImage(uploadId: string, threadId: string): Promise<ImageReadResult>;
12
27
  /**
13
28
  * Uploads a file and returns the created {@link Attachment}.
14
29
  *
@@ -23,4 +23,5 @@ export declare const ENDPOINT_REACTIONS = "reactions";
23
23
  export declare const ENDPOINT_SEARCH = "search";
24
24
  export declare const ENDPOINT_CONVERSATION_MESSAGES = "conversation_messages";
25
25
  export declare const ENDPOINT_ATTACHMENTS = "attachments";
26
+ export declare const ENDPOINT_FILES = "files";
26
27
  export declare const ENDPOINT_HOOKS = "hooks";
@@ -1,6 +1,6 @@
1
1
  export * from './authentication.js';
2
2
  export * from './migration.js';
3
- export { AttachmentsClient } from './clients/attachments-client.js';
3
+ export { AttachmentsClient, IMAGE_READ_MIME_TYPES, ImageReadResultSchema, type ImageReadMimeType, type ImageReadResult, } from './clients/attachments-client.js';
4
4
  export { ChannelsClient } from './clients/channels-client.js';
5
5
  export { CommentsClient } from './clients/comments-client.js';
6
6
  export { ConversationMessagesClient } from './clients/conversation-messages-client.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doist/comms-sdk",
3
- "version": "3.0.2",
3
+ "version": "3.2.0",
4
4
  "description": "A TypeScript wrapper for the Comms REST API.",
5
5
  "author": "Doist developers",
6
6
  "homepage": "https://doist.github.io/comms-sdk-typescript/",