@doist/comms-sdk 0.11.0 → 1.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.
@@ -24,7 +24,11 @@ const notify_audience_1 = require("./notify-audience");
24
24
  */
25
25
  function addCommentRequest(context, params, options) {
26
26
  const normalized = (0, notify_audience_1.applyNotifyAudience)(params);
27
- const withId = { ...normalized, id: (0, uuidv7_1.resolveCreateId)(normalized.id) };
27
+ const withId = {
28
+ ...normalized,
29
+ id: (0, uuidv7_1.resolveCreateId)(normalized.id),
30
+ threadId: (0, uuidv7_1.resolveReferenceId)(normalized.threadId, 'threadId'),
31
+ };
28
32
  const payload = options?.threadAction
29
33
  ? { ...withId, threadAction: options.threadAction }
30
34
  : withId;
@@ -116,7 +116,11 @@ class ThreadsClient extends base_client_1.BaseClient {
116
116
  */
117
117
  createThread(args) {
118
118
  const normalized = (0, notify_audience_1.applyNotifyAudience)(args);
119
- return this.simple('POST', 'add', { ...normalized, id: (0, uuidv7_1.resolveCreateId)(args.id) }, this.threadSchema);
119
+ return this.simple('POST', 'add', {
120
+ ...normalized,
121
+ id: (0, uuidv7_1.resolveCreateId)(normalized.id),
122
+ channelId: (0, uuidv7_1.resolveReferenceId)(normalized.channelId, 'channelId'),
123
+ }, this.threadSchema);
120
124
  }
121
125
  /**
122
126
  * Partial update of an existing thread.
@@ -344,7 +348,7 @@ class ThreadsClient extends base_client_1.BaseClient {
344
348
  apiToken: this.apiToken,
345
349
  customFetch: this.customFetch,
346
350
  schema: this.commentSchema,
347
- }, { threadId: id, ...rest }, { threadAction });
351
+ }, { threadId: (0, uuidv7_1.resolveReferenceId)(id, 'id'), ...rest }, { threadAction });
348
352
  }
349
353
  simple(httpMethod, suffix, params, schema) {
350
354
  return (0, http_client_1.request)({
@@ -4,9 +4,11 @@ exports.mockWorkspaceUser = exports.mockComment = exports.mockConversation = exp
4
4
  const endpoints_1 = require("../consts/endpoints");
5
5
  exports.TEST_API_TOKEN = 'test-api-token';
6
6
  exports.TEST_API_BASE_URL = (0, endpoints_1.getCommsBaseUri)().replace(/\/$/, '');
7
- // Canonical test IDs — shaped so they pass SDK-side validation.
8
- exports.TEST_CHANNEL_ID = '7YpL3oZ4kZ9vP7Q1tR2sX3y';
9
- exports.TEST_THREAD_ID = '7YpL3oZ4kZ9vP7Q1tR2sX3z';
7
+ // Stable test IDs. TEST_CHANNEL_ID and TEST_THREAD_ID are base58
8
+ // UUIDv7-shaped because create-thread and add-comment paths validate them
9
+ // SDK-side.
10
+ exports.TEST_CHANNEL_ID = 'CQ7yksHFbYFrSPVTaHVCs';
11
+ exports.TEST_THREAD_ID = 'CQ7yksHFbYFrSPVTaHVCt';
10
12
  exports.TEST_COMMENT_ID = '7YpL3oZ4kZ9vP7Q1tR2sX41';
11
13
  exports.TEST_CONVERSATION_ID = '7YpL3oZ4kZ9vP7Q1tR2sX42';
12
14
  exports.TEST_MESSAGE_ID = '7YpL3oZ4kZ9vP7Q1tR2sX43';
@@ -4,6 +4,7 @@ exports.UuidV7Error = void 0;
4
4
  exports.encodeUuidToBase58 = encodeUuidToBase58;
5
5
  exports.decodeBase58ToUuidBytes = decodeBase58ToUuidBytes;
6
6
  exports.generateId = generateId;
7
+ exports.resolveReferenceId = resolveReferenceId;
7
8
  exports.resolveCreateId = resolveCreateId;
8
9
  exports.isValidUuidV7Base58 = isValidUuidV7Base58;
9
10
  exports.base58FromUuidString = base58FromUuidString;
@@ -112,6 +113,13 @@ function generateId() {
112
113
  const hex = (0, uuid_1.v7)().replace(/-/g, '');
113
114
  return encodeUuidToBase58(hexToBytes(hex));
114
115
  }
116
+ /** Validate an existing entity ID without minting a replacement. */
117
+ function resolveReferenceId(id, fieldName) {
118
+ if (!isValidUuidV7Base58(id)) {
119
+ throw new UuidV7Error(`invalid ${fieldName} ${JSON.stringify(id)} — use a base58 UUIDv7 value for \`${fieldName}\`.`);
120
+ }
121
+ return id;
122
+ }
115
123
  /**
116
124
  * Resolve the `id` for a create-style API call: validate the caller-supplied
117
125
  * value (throwing {@link UuidV7Error} before the request leaves the SDK) or
@@ -1,6 +1,6 @@
1
1
  import { ENDPOINT_COMMENTS } from '../consts/endpoints.js';
2
2
  import { request } from '../transport/http-client.js';
3
- import { resolveCreateId } from '../utils/uuidv7.js';
3
+ import { resolveCreateId, resolveReferenceId } from '../utils/uuidv7.js';
4
4
  import { applyNotifyAudience } from './notify-audience.js';
5
5
  /**
6
6
  * Internal helper that powers `comments.createComment`,
@@ -21,7 +21,11 @@ import { applyNotifyAudience } from './notify-audience.js';
21
21
  */
22
22
  export function addCommentRequest(context, params, options) {
23
23
  const normalized = applyNotifyAudience(params);
24
- const withId = { ...normalized, id: resolveCreateId(normalized.id) };
24
+ const withId = {
25
+ ...normalized,
26
+ id: resolveCreateId(normalized.id),
27
+ threadId: resolveReferenceId(normalized.threadId, 'threadId'),
28
+ };
25
29
  const payload = options?.threadAction
26
30
  ? { ...withId, threadAction: options.threadAction }
27
31
  : withId;
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  import { ENDPOINT_THREADS } from '../consts/endpoints.js';
3
3
  import { request } from '../transport/http-client.js';
4
4
  import { CommentSchema, createCommentSchema, createThreadSchema, StatusOkSchema, ThreadSchema, UnreadThreadSchema, } from '../types/entities.js';
5
- import { resolveCreateId } from '../utils/uuidv7.js';
5
+ import { resolveCreateId, resolveReferenceId } from '../utils/uuidv7.js';
6
6
  import { addCommentRequest } from './add-comment-helper.js';
7
7
  import { BaseClient } from './base-client.js';
8
8
  import { applyNotifyAudience } from './notify-audience.js';
@@ -113,7 +113,11 @@ export class ThreadsClient extends BaseClient {
113
113
  */
114
114
  createThread(args) {
115
115
  const normalized = applyNotifyAudience(args);
116
- return this.simple('POST', 'add', { ...normalized, id: resolveCreateId(args.id) }, this.threadSchema);
116
+ return this.simple('POST', 'add', {
117
+ ...normalized,
118
+ id: resolveCreateId(normalized.id),
119
+ channelId: resolveReferenceId(normalized.channelId, 'channelId'),
120
+ }, this.threadSchema);
117
121
  }
118
122
  /**
119
123
  * Partial update of an existing thread.
@@ -341,7 +345,7 @@ export class ThreadsClient extends BaseClient {
341
345
  apiToken: this.apiToken,
342
346
  customFetch: this.customFetch,
343
347
  schema: this.commentSchema,
344
- }, { threadId: id, ...rest }, { threadAction });
348
+ }, { threadId: resolveReferenceId(id, 'id'), ...rest }, { threadAction });
345
349
  }
346
350
  simple(httpMethod, suffix, params, schema) {
347
351
  return request({
@@ -1,9 +1,11 @@
1
1
  import { getCommsBaseUri } from '../consts/endpoints.js';
2
2
  export const TEST_API_TOKEN = 'test-api-token';
3
3
  export const TEST_API_BASE_URL = getCommsBaseUri().replace(/\/$/, '');
4
- // Canonical test IDs — shaped so they pass SDK-side validation.
5
- export const TEST_CHANNEL_ID = '7YpL3oZ4kZ9vP7Q1tR2sX3y';
6
- export const TEST_THREAD_ID = '7YpL3oZ4kZ9vP7Q1tR2sX3z';
4
+ // Stable test IDs. TEST_CHANNEL_ID and TEST_THREAD_ID are base58
5
+ // UUIDv7-shaped because create-thread and add-comment paths validate them
6
+ // SDK-side.
7
+ export const TEST_CHANNEL_ID = 'CQ7yksHFbYFrSPVTaHVCs';
8
+ export const TEST_THREAD_ID = 'CQ7yksHFbYFrSPVTaHVCt';
7
9
  export const TEST_COMMENT_ID = '7YpL3oZ4kZ9vP7Q1tR2sX41';
8
10
  export const TEST_CONVERSATION_ID = '7YpL3oZ4kZ9vP7Q1tR2sX42';
9
11
  export const TEST_MESSAGE_ID = '7YpL3oZ4kZ9vP7Q1tR2sX43';
@@ -101,6 +101,13 @@ export function generateId() {
101
101
  const hex = uuidv7().replace(/-/g, '');
102
102
  return encodeUuidToBase58(hexToBytes(hex));
103
103
  }
104
+ /** Validate an existing entity ID without minting a replacement. */
105
+ export function resolveReferenceId(id, fieldName) {
106
+ if (!isValidUuidV7Base58(id)) {
107
+ throw new UuidV7Error(`invalid ${fieldName} ${JSON.stringify(id)} — use a base58 UUIDv7 value for \`${fieldName}\`.`);
108
+ }
109
+ return id;
110
+ }
104
111
  /**
105
112
  * Resolve the `id` for a create-style API call: validate the caller-supplied
106
113
  * value (throwing {@link UuidV7Error} before the request leaves the SDK) or
@@ -1,8 +1,8 @@
1
1
  import type { Channel, Comment, Conversation, Group, Thread, User, Workspace, WorkspaceUser } from '../types/entities.js';
2
2
  export declare const TEST_API_TOKEN = "test-api-token";
3
3
  export declare const TEST_API_BASE_URL: string;
4
- export declare const TEST_CHANNEL_ID = "7YpL3oZ4kZ9vP7Q1tR2sX3y";
5
- export declare const TEST_THREAD_ID = "7YpL3oZ4kZ9vP7Q1tR2sX3z";
4
+ export declare const TEST_CHANNEL_ID = "CQ7yksHFbYFrSPVTaHVCs";
5
+ export declare const TEST_THREAD_ID = "CQ7yksHFbYFrSPVTaHVCt";
6
6
  export declare const TEST_COMMENT_ID = "7YpL3oZ4kZ9vP7Q1tR2sX41";
7
7
  export declare const TEST_CONVERSATION_ID = "7YpL3oZ4kZ9vP7Q1tR2sX42";
8
8
  export declare const TEST_MESSAGE_ID = "7YpL3oZ4kZ9vP7Q1tR2sX43";
@@ -14,6 +14,8 @@ export declare function decodeBase58ToUuidBytes(value: string): Uint8Array;
14
14
  * group — the backend requires the client to supply the ID on create.
15
15
  */
16
16
  export declare function generateId(): string;
17
+ /** Validate an existing entity ID without minting a replacement. */
18
+ export declare function resolveReferenceId(id: string, fieldName: string): string;
17
19
  /**
18
20
  * Resolve the `id` for a create-style API call: validate the caller-supplied
19
21
  * value (throwing {@link UuidV7Error} before the request leaves the SDK) or
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doist/comms-sdk",
3
- "version": "0.11.0",
3
+ "version": "1.0.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/",
@@ -12,7 +12,8 @@
12
12
  "license": "MIT",
13
13
  "type": "module",
14
14
  "engines": {
15
- "node": ">=20.18.1"
15
+ "node": ">=24",
16
+ "npm": ">=11"
16
17
  },
17
18
  "main": "dist/cjs/index.js",
18
19
  "module": "dist/esm/index.js",