@doist/comms-sdk 1.0.1 → 2.0.1

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.
@@ -143,7 +143,7 @@ class ConversationsClient extends base_client_1.BaseClient {
143
143
  * @returns The updated conversation object.
144
144
  */
145
145
  archiveConversation(id) {
146
- return this.simple('GET', 'archive', { id }, this.conversationSchema);
146
+ return this.simple('POST', 'archive', { id }, this.conversationSchema);
147
147
  }
148
148
  /**
149
149
  * Unarchives a conversation.
@@ -152,7 +152,7 @@ class ConversationsClient extends base_client_1.BaseClient {
152
152
  * @returns The updated conversation object.
153
153
  */
154
154
  unarchiveConversation(id) {
155
- return this.simple('GET', 'unarchive', { id }, this.conversationSchema);
155
+ return this.simple('POST', 'unarchive', { id }, this.conversationSchema);
156
156
  }
157
157
  /**
158
158
  * Adds a user to a conversation.
@@ -65,12 +65,13 @@ class WorkspaceUsersClient extends base_client_1.BaseClient {
65
65
  * @param args - The arguments for getting a user by ID.
66
66
  * @param args.workspaceId - The workspace ID.
67
67
  * @param args.userId - The user's ID.
68
- * @returns The workspace user object.
68
+ * @returns The workspace user object, reduced to the restricted shape when
69
+ * the viewer may not see the user's full profile.
69
70
  *
70
71
  * @example
71
72
  * ```typescript
72
73
  * const user = await api.workspaceUsers.getUserById({ workspaceId: 123, userId: 456 })
73
- * console.log(user.fullName, user.email)
74
+ * console.log(user.fullName, isRestrictedWorkspaceUser(user) ? null : user.email)
74
75
  * ```
75
76
  */
76
77
  getUserById(args) {
@@ -81,7 +82,7 @@ class WorkspaceUsersClient extends base_client_1.BaseClient {
81
82
  apiToken: this.apiToken,
82
83
  payload: { id: args.workspaceId, user_id: args.userId },
83
84
  customFetch: this.customFetch,
84
- }).then((response) => entities_1.WorkspaceUserSchema.parse(response.data));
85
+ }).then((response) => entities_1.VisibleWorkspaceUserSchema.parse(response.data));
85
86
  }
86
87
  /**
87
88
  * Gets a user by email.
@@ -89,7 +90,8 @@ class WorkspaceUsersClient extends base_client_1.BaseClient {
89
90
  * @param args - The arguments for getting a user by email.
90
91
  * @param args.workspaceId - The workspace ID.
91
92
  * @param args.email - The user's email.
92
- * @returns The workspace user object.
93
+ * @returns The workspace user object, reduced to the restricted shape when
94
+ * the viewer may not see the user's full profile.
93
95
  *
94
96
  * @example
95
97
  * ```typescript
@@ -107,7 +109,7 @@ class WorkspaceUsersClient extends base_client_1.BaseClient {
107
109
  apiToken: this.apiToken,
108
110
  payload: { id: args.workspaceId, email: args.email },
109
111
  customFetch: this.customFetch,
110
- }).then((response) => entities_1.WorkspaceUserSchema.parse(response.data));
112
+ }).then((response) => entities_1.VisibleWorkspaceUserSchema.parse(response.data));
111
113
  }
112
114
  /**
113
115
  * Gets the user's info in the context of the workspace.
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SearchResultSchema = exports.ConversationSearchResultSchema = exports.ThreadSearchResultSchema = exports.SEARCH_RESULT_TYPES = exports.UnreadConversationSchema = exports.UnreadThreadSchema = exports.InboxThreadSchema = exports.ConversationMessageSchema = exports.ConversationMessageObjectSchema = exports.WorkspaceUserSchema = exports.CommentSchema = exports.CommentObjectSchema = exports.ConversationSchema = exports.ConversationObjectSchema = exports.GroupSchema = exports.ThreadSchema = exports.ThreadObjectSchema = exports.ChannelSchema = exports.ChannelObjectSchema = exports.WorkspaceSchema = exports.UserSchema = exports.BaseUserSchema = exports.RequestAttachmentSchema = exports.AttachmentSchema = exports.HookSubscribeResponseSchema = exports.StatusOkSchema = exports.SystemMessageSchema = void 0;
3
+ exports.SearchResultSchema = exports.ConversationSearchResultSchema = exports.ThreadSearchResultSchema = exports.SEARCH_RESULT_TYPES = exports.UnreadConversationSchema = exports.UnreadThreadSchema = exports.InboxThreadSchema = exports.ConversationMessageSchema = exports.ConversationMessageObjectSchema = exports.VisibleWorkspaceUserSchema = exports.RestrictedWorkspaceUserSchema = exports.WorkspaceUserSchema = exports.CommentSchema = exports.CommentObjectSchema = exports.ConversationSchema = exports.ConversationObjectSchema = exports.GroupSchema = exports.ThreadSchema = exports.ThreadObjectSchema = exports.ChannelSchema = exports.ChannelObjectSchema = exports.WorkspaceSchema = exports.UserSchema = exports.BaseUserSchema = exports.RequestAttachmentSchema = exports.AttachmentSchema = exports.HookSubscribeResponseSchema = exports.StatusOkSchema = exports.SystemMessageSchema = void 0;
4
4
  exports.createChannelSchema = createChannelSchema;
5
5
  exports.createThreadSchema = createThreadSchema;
6
6
  exports.createConversationSchema = createConversationSchema;
7
7
  exports.createCommentSchema = createCommentSchema;
8
+ exports.isRestrictedWorkspaceUser = isRestrictedWorkspaceUser;
8
9
  exports.createConversationMessageSchema = createConversationMessageSchema;
9
10
  exports.createInboxThreadObjectSchema = createInboxThreadObjectSchema;
10
11
  exports.createInboxThreadSchema = createInboxThreadSchema;
@@ -319,6 +320,39 @@ exports.WorkspaceUserSchema = exports.BaseUserSchema.extend({
319
320
  timeFormat: zod_1.z.string().nullable().optional(),
320
321
  version: zod_1.z.number(),
321
322
  });
323
+ // Reduced user shape the backend substitutes when the viewer may not see a
324
+ // user's full profile — the user has been removed from the workspace, or the
325
+ // viewer is a guest with no visibility of them. `full_name` / `short_name`
326
+ // carry the first name only, and neither `timezone` nor `user_type` is sent,
327
+ // so those cannot be modelled on this branch.
328
+ exports.RestrictedWorkspaceUserSchema = exports.BaseUserSchema.omit({ timezone: true }).extend({
329
+ restricted: zod_1.z.literal(true),
330
+ version: zod_1.z.number(),
331
+ });
332
+ // A workspace user as the current viewer sees them. Endpoints that resolve a
333
+ // single user by id or email return either shape, discriminated by
334
+ // `restricted`; narrow with {@link isRestrictedWorkspaceUser}. Endpoints that
335
+ // list a workspace's own members always return the full shape.
336
+ exports.VisibleWorkspaceUserSchema = zod_1.z.union([
337
+ exports.WorkspaceUserSchema,
338
+ exports.RestrictedWorkspaceUserSchema,
339
+ ]);
340
+ /**
341
+ * Narrows a {@link VisibleWorkspaceUser} to the reduced shape, which has no
342
+ * `timezone` and no `userType`.
343
+ *
344
+ * @param user - The user to check.
345
+ * @returns `true` when the viewer only gets the restricted profile.
346
+ *
347
+ * @example
348
+ * ```typescript
349
+ * const user = await api.workspaceUsers.getUserById({ workspaceId: 123, userId: 456 })
350
+ * const zone = isRestrictedWorkspaceUser(user) ? 'UTC' : user.timezone
351
+ * ```
352
+ */
353
+ function isRestrictedWorkspaceUser(user) {
354
+ return user.restricted === true;
355
+ }
322
356
  // ConversationMessage entity from API. `id` is widened to `string | number`
323
357
  // (coerced to a string post-parse) because the backend currently emits
324
358
  // either shape depending on the endpoint; the URL/reaction helpers accept
@@ -140,7 +140,7 @@ export class ConversationsClient extends BaseClient {
140
140
  * @returns The updated conversation object.
141
141
  */
142
142
  archiveConversation(id) {
143
- return this.simple('GET', 'archive', { id }, this.conversationSchema);
143
+ return this.simple('POST', 'archive', { id }, this.conversationSchema);
144
144
  }
145
145
  /**
146
146
  * Unarchives a conversation.
@@ -149,7 +149,7 @@ export class ConversationsClient extends BaseClient {
149
149
  * @returns The updated conversation object.
150
150
  */
151
151
  unarchiveConversation(id) {
152
- return this.simple('GET', 'unarchive', { id }, this.conversationSchema);
152
+ return this.simple('POST', 'unarchive', { id }, this.conversationSchema);
153
153
  }
154
154
  /**
155
155
  * Adds a user to a conversation.
@@ -1,5 +1,5 @@
1
1
  import { request } from '../transport/http-client.js';
2
- import { WorkspaceUserSchema } from '../types/entities.js';
2
+ import { VisibleWorkspaceUserSchema, WorkspaceUserSchema, } from '../types/entities.js';
3
3
  import { BaseClient } from './base-client.js';
4
4
  /**
5
5
  * Client for `/api/v1/workspace_users/`. The backend's `add` endpoint
@@ -62,12 +62,13 @@ export class WorkspaceUsersClient extends BaseClient {
62
62
  * @param args - The arguments for getting a user by ID.
63
63
  * @param args.workspaceId - The workspace ID.
64
64
  * @param args.userId - The user's ID.
65
- * @returns The workspace user object.
65
+ * @returns The workspace user object, reduced to the restricted shape when
66
+ * the viewer may not see the user's full profile.
66
67
  *
67
68
  * @example
68
69
  * ```typescript
69
70
  * const user = await api.workspaceUsers.getUserById({ workspaceId: 123, userId: 456 })
70
- * console.log(user.fullName, user.email)
71
+ * console.log(user.fullName, isRestrictedWorkspaceUser(user) ? null : user.email)
71
72
  * ```
72
73
  */
73
74
  getUserById(args) {
@@ -78,7 +79,7 @@ export class WorkspaceUsersClient extends BaseClient {
78
79
  apiToken: this.apiToken,
79
80
  payload: { id: args.workspaceId, user_id: args.userId },
80
81
  customFetch: this.customFetch,
81
- }).then((response) => WorkspaceUserSchema.parse(response.data));
82
+ }).then((response) => VisibleWorkspaceUserSchema.parse(response.data));
82
83
  }
83
84
  /**
84
85
  * Gets a user by email.
@@ -86,7 +87,8 @@ export class WorkspaceUsersClient extends BaseClient {
86
87
  * @param args - The arguments for getting a user by email.
87
88
  * @param args.workspaceId - The workspace ID.
88
89
  * @param args.email - The user's email.
89
- * @returns The workspace user object.
90
+ * @returns The workspace user object, reduced to the restricted shape when
91
+ * the viewer may not see the user's full profile.
90
92
  *
91
93
  * @example
92
94
  * ```typescript
@@ -104,7 +106,7 @@ export class WorkspaceUsersClient extends BaseClient {
104
106
  apiToken: this.apiToken,
105
107
  payload: { id: args.workspaceId, email: args.email },
106
108
  customFetch: this.customFetch,
107
- }).then((response) => WorkspaceUserSchema.parse(response.data));
109
+ }).then((response) => VisibleWorkspaceUserSchema.parse(response.data));
108
110
  }
109
111
  /**
110
112
  * Gets the user's info in the context of the workspace.
@@ -309,6 +309,39 @@ export const WorkspaceUserSchema = BaseUserSchema.extend({
309
309
  timeFormat: z.string().nullable().optional(),
310
310
  version: z.number(),
311
311
  });
312
+ // Reduced user shape the backend substitutes when the viewer may not see a
313
+ // user's full profile — the user has been removed from the workspace, or the
314
+ // viewer is a guest with no visibility of them. `full_name` / `short_name`
315
+ // carry the first name only, and neither `timezone` nor `user_type` is sent,
316
+ // so those cannot be modelled on this branch.
317
+ export const RestrictedWorkspaceUserSchema = BaseUserSchema.omit({ timezone: true }).extend({
318
+ restricted: z.literal(true),
319
+ version: z.number(),
320
+ });
321
+ // A workspace user as the current viewer sees them. Endpoints that resolve a
322
+ // single user by id or email return either shape, discriminated by
323
+ // `restricted`; narrow with {@link isRestrictedWorkspaceUser}. Endpoints that
324
+ // list a workspace's own members always return the full shape.
325
+ export const VisibleWorkspaceUserSchema = z.union([
326
+ WorkspaceUserSchema,
327
+ RestrictedWorkspaceUserSchema,
328
+ ]);
329
+ /**
330
+ * Narrows a {@link VisibleWorkspaceUser} to the reduced shape, which has no
331
+ * `timezone` and no `userType`.
332
+ *
333
+ * @param user - The user to check.
334
+ * @returns `true` when the viewer only gets the restricted profile.
335
+ *
336
+ * @example
337
+ * ```typescript
338
+ * const user = await api.workspaceUsers.getUserById({ workspaceId: 123, userId: 456 })
339
+ * const zone = isRestrictedWorkspaceUser(user) ? 'UTC' : user.timezone
340
+ * ```
341
+ */
342
+ export function isRestrictedWorkspaceUser(user) {
343
+ return user.restricted === true;
344
+ }
312
345
  // ConversationMessage entity from API. `id` is widened to `string | number`
313
346
  // (coerced to a string post-parse) because the backend currently emits
314
347
  // either shape depending on the endpoint; the URL/reaction helpers accept
@@ -1,4 +1,4 @@
1
- import { type WorkspaceUser } from '../types/entities.js';
1
+ import { type VisibleWorkspaceUser, type WorkspaceUser } from '../types/entities.js';
2
2
  import { UserType } from '../types/enums.js';
3
3
  import type { GetUserByEmailArgs, GetUserByIdArgs, GetUserInfoArgs, GetUserLocalTimeArgs, GetWorkspaceUsersArgs } from '../types/requests.js';
4
4
  import { BaseClient } from './base-client.js';
@@ -39,22 +39,24 @@ export declare class WorkspaceUsersClient extends BaseClient {
39
39
  * @param args - The arguments for getting a user by ID.
40
40
  * @param args.workspaceId - The workspace ID.
41
41
  * @param args.userId - The user's ID.
42
- * @returns The workspace user object.
42
+ * @returns The workspace user object, reduced to the restricted shape when
43
+ * the viewer may not see the user's full profile.
43
44
  *
44
45
  * @example
45
46
  * ```typescript
46
47
  * const user = await api.workspaceUsers.getUserById({ workspaceId: 123, userId: 456 })
47
- * console.log(user.fullName, user.email)
48
+ * console.log(user.fullName, isRestrictedWorkspaceUser(user) ? null : user.email)
48
49
  * ```
49
50
  */
50
- getUserById(args: GetUserByIdArgs): Promise<WorkspaceUser>;
51
+ getUserById(args: GetUserByIdArgs): Promise<VisibleWorkspaceUser>;
51
52
  /**
52
53
  * Gets a user by email.
53
54
  *
54
55
  * @param args - The arguments for getting a user by email.
55
56
  * @param args.workspaceId - The workspace ID.
56
57
  * @param args.email - The user's email.
57
- * @returns The workspace user object.
58
+ * @returns The workspace user object, reduced to the restricted shape when
59
+ * the viewer may not see the user's full profile.
58
60
  *
59
61
  * @example
60
62
  * ```typescript
@@ -64,7 +66,7 @@ export declare class WorkspaceUsersClient extends BaseClient {
64
66
  * })
65
67
  * ```
66
68
  */
67
- getUserByEmail(args: GetUserByEmailArgs): Promise<WorkspaceUser>;
69
+ getUserByEmail(args: GetUserByEmailArgs): Promise<VisibleWorkspaceUser>;
68
70
  /**
69
71
  * Gets the user's info in the context of the workspace.
70
72
  *
@@ -1603,6 +1603,82 @@ export declare const WorkspaceUserSchema: z.ZodObject<{
1603
1603
  version: z.ZodNumber;
1604
1604
  }, z.core.$strip>;
1605
1605
  export type WorkspaceUser = z.infer<typeof WorkspaceUserSchema>;
1606
+ export declare const RestrictedWorkspaceUserSchema: z.ZodObject<{
1607
+ id: z.ZodNumber;
1608
+ fullName: z.ZodString;
1609
+ shortName: z.ZodString;
1610
+ firstName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1611
+ removed: z.ZodBoolean;
1612
+ imageId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1613
+ avatarUrls: z.ZodOptional<z.ZodNullable<z.ZodObject<{
1614
+ s35: z.ZodString;
1615
+ s60: z.ZodString;
1616
+ s195: z.ZodString;
1617
+ s640: z.ZodString;
1618
+ }, z.core.$strip>>>;
1619
+ setupPending: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
1620
+ restricted: z.ZodLiteral<true>;
1621
+ version: z.ZodNumber;
1622
+ }, z.core.$strip>;
1623
+ export type RestrictedWorkspaceUser = z.infer<typeof RestrictedWorkspaceUserSchema>;
1624
+ export declare const VisibleWorkspaceUserSchema: z.ZodUnion<readonly [z.ZodObject<{
1625
+ id: z.ZodNumber;
1626
+ fullName: z.ZodString;
1627
+ shortName: z.ZodString;
1628
+ firstName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1629
+ timezone: z.ZodString;
1630
+ removed: z.ZodBoolean;
1631
+ imageId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1632
+ avatarUrls: z.ZodOptional<z.ZodNullable<z.ZodObject<{
1633
+ s35: z.ZodString;
1634
+ s60: z.ZodString;
1635
+ s195: z.ZodString;
1636
+ s640: z.ZodString;
1637
+ }, z.core.$strip>>>;
1638
+ restricted: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
1639
+ setupPending: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
1640
+ email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1641
+ userType: z.ZodEnum<{
1642
+ USER: "USER";
1643
+ GUEST: "GUEST";
1644
+ ADMIN: "ADMIN";
1645
+ }>;
1646
+ dateFormat: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1647
+ theme: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
1648
+ timeFormat: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1649
+ version: z.ZodNumber;
1650
+ }, z.core.$strip>, z.ZodObject<{
1651
+ id: z.ZodNumber;
1652
+ fullName: z.ZodString;
1653
+ shortName: z.ZodString;
1654
+ firstName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1655
+ removed: z.ZodBoolean;
1656
+ imageId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1657
+ avatarUrls: z.ZodOptional<z.ZodNullable<z.ZodObject<{
1658
+ s35: z.ZodString;
1659
+ s60: z.ZodString;
1660
+ s195: z.ZodString;
1661
+ s640: z.ZodString;
1662
+ }, z.core.$strip>>>;
1663
+ setupPending: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
1664
+ restricted: z.ZodLiteral<true>;
1665
+ version: z.ZodNumber;
1666
+ }, z.core.$strip>]>;
1667
+ export type VisibleWorkspaceUser = z.infer<typeof VisibleWorkspaceUserSchema>;
1668
+ /**
1669
+ * Narrows a {@link VisibleWorkspaceUser} to the reduced shape, which has no
1670
+ * `timezone` and no `userType`.
1671
+ *
1672
+ * @param user - The user to check.
1673
+ * @returns `true` when the viewer only gets the restricted profile.
1674
+ *
1675
+ * @example
1676
+ * ```typescript
1677
+ * const user = await api.workspaceUsers.getUserById({ workspaceId: 123, userId: 456 })
1678
+ * const zone = isRestrictedWorkspaceUser(user) ? 'UTC' : user.timezone
1679
+ * ```
1680
+ */
1681
+ export declare function isRestrictedWorkspaceUser(user: VisibleWorkspaceUser): user is RestrictedWorkspaceUser;
1606
1682
  export declare const ConversationMessageObjectSchema: z.ZodObject<{
1607
1683
  id: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>;
1608
1684
  content: z.ZodString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doist/comms-sdk",
3
- "version": "1.0.1",
3
+ "version": "2.0.1",
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/",
@@ -49,7 +49,7 @@
49
49
  "dependencies": {
50
50
  "camelcase": "9.0.0",
51
51
  "ts-custom-error": "3.3.1",
52
- "undici": "7.28.0",
52
+ "undici": "7.29.0",
53
53
  "uuid": "11.1.1",
54
54
  "zod": "4.4.3"
55
55
  },