@doist/comms-sdk 0.0.1 → 0.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.
Files changed (115) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +143 -45
  3. package/dist/cjs/authentication.js +211 -0
  4. package/dist/cjs/clients/add-comment-helper.js +70 -0
  5. package/dist/cjs/clients/base-client.js +25 -0
  6. package/dist/cjs/clients/channels-client.js +200 -0
  7. package/dist/cjs/clients/comments-client.js +159 -0
  8. package/dist/cjs/clients/conversation-messages-client.js +158 -0
  9. package/dist/cjs/clients/conversations-client.js +243 -0
  10. package/dist/cjs/clients/groups-client.js +164 -0
  11. package/dist/cjs/clients/inbox-client.js +171 -0
  12. package/dist/cjs/clients/reactions-client.js +97 -0
  13. package/dist/cjs/clients/search-client.js +138 -0
  14. package/dist/cjs/clients/threads-client.js +330 -0
  15. package/dist/cjs/clients/users-client.js +326 -0
  16. package/dist/cjs/clients/workspace-users-client.js +240 -0
  17. package/dist/cjs/clients/workspaces-client.js +166 -0
  18. package/dist/cjs/comms-api.js +66 -0
  19. package/dist/cjs/consts/endpoints.js +32 -0
  20. package/dist/cjs/index.js +48 -0
  21. package/dist/cjs/package.json +1 -0
  22. package/dist/cjs/testUtils/msw-handlers.js +51 -0
  23. package/dist/cjs/testUtils/msw-setup.js +21 -0
  24. package/dist/cjs/testUtils/obsidian-fetch-adapter.js +53 -0
  25. package/dist/cjs/testUtils/test-defaults.js +104 -0
  26. package/dist/cjs/transport/fetch-with-retry.js +136 -0
  27. package/dist/cjs/transport/http-client.js +56 -0
  28. package/dist/cjs/transport/http-dispatcher.js +143 -0
  29. package/dist/cjs/types/api-version.js +8 -0
  30. package/dist/cjs/types/entities.js +411 -0
  31. package/dist/cjs/types/enums.js +37 -0
  32. package/dist/cjs/types/errors.js +12 -0
  33. package/dist/cjs/types/http.js +4 -0
  34. package/dist/cjs/types/index.js +22 -0
  35. package/dist/cjs/types/requests.js +116 -0
  36. package/dist/cjs/utils/case-conversion.js +54 -0
  37. package/dist/cjs/utils/index.js +19 -0
  38. package/dist/cjs/utils/timestamp-conversion.js +49 -0
  39. package/dist/cjs/utils/url-helpers.js +131 -0
  40. package/dist/cjs/utils/uuidv7.js +174 -0
  41. package/dist/esm/authentication.js +203 -0
  42. package/dist/esm/clients/add-comment-helper.js +67 -0
  43. package/dist/esm/clients/base-client.js +21 -0
  44. package/dist/esm/clients/channels-client.js +196 -0
  45. package/dist/esm/clients/comments-client.js +155 -0
  46. package/dist/esm/clients/conversation-messages-client.js +154 -0
  47. package/dist/esm/clients/conversations-client.js +239 -0
  48. package/dist/esm/clients/groups-client.js +160 -0
  49. package/dist/esm/clients/inbox-client.js +167 -0
  50. package/dist/esm/clients/reactions-client.js +93 -0
  51. package/dist/esm/clients/search-client.js +134 -0
  52. package/dist/esm/clients/threads-client.js +326 -0
  53. package/dist/esm/clients/users-client.js +322 -0
  54. package/dist/esm/clients/workspace-users-client.js +236 -0
  55. package/dist/esm/clients/workspaces-client.js +162 -0
  56. package/dist/esm/comms-api.js +62 -0
  57. package/dist/esm/consts/endpoints.js +28 -0
  58. package/dist/esm/index.js +17 -0
  59. package/dist/esm/testUtils/msw-handlers.js +45 -0
  60. package/dist/esm/testUtils/msw-setup.js +18 -0
  61. package/dist/esm/testUtils/obsidian-fetch-adapter.js +50 -0
  62. package/dist/esm/testUtils/test-defaults.js +101 -0
  63. package/dist/esm/transport/fetch-with-retry.js +133 -0
  64. package/dist/esm/transport/http-client.js +51 -0
  65. package/dist/esm/transport/http-dispatcher.js +104 -0
  66. package/dist/esm/types/api-version.js +5 -0
  67. package/dist/esm/types/entities.js +408 -0
  68. package/dist/esm/types/enums.js +34 -0
  69. package/dist/esm/types/errors.js +8 -0
  70. package/dist/esm/types/http.js +1 -0
  71. package/dist/esm/types/index.js +6 -0
  72. package/dist/esm/types/requests.js +113 -0
  73. package/dist/esm/utils/case-conversion.js +47 -0
  74. package/dist/esm/utils/index.js +3 -0
  75. package/dist/esm/utils/timestamp-conversion.js +45 -0
  76. package/dist/esm/utils/url-helpers.js +112 -0
  77. package/dist/esm/utils/uuidv7.js +163 -0
  78. package/dist/types/authentication.d.ts +160 -0
  79. package/dist/types/clients/add-comment-helper.d.ts +29 -0
  80. package/dist/types/clients/base-client.d.ts +28 -0
  81. package/dist/types/clients/channels-client.d.ts +208 -0
  82. package/dist/types/clients/comments-client.d.ts +224 -0
  83. package/dist/types/clients/conversation-messages-client.d.ts +198 -0
  84. package/dist/types/clients/conversations-client.d.ts +346 -0
  85. package/dist/types/clients/groups-client.d.ts +148 -0
  86. package/dist/types/clients/inbox-client.d.ts +96 -0
  87. package/dist/types/clients/reactions-client.d.ts +57 -0
  88. package/dist/types/clients/search-client.d.ts +70 -0
  89. package/dist/types/clients/threads-client.d.ts +536 -0
  90. package/dist/types/clients/users-client.d.ts +250 -0
  91. package/dist/types/clients/workspace-users-client.d.ts +147 -0
  92. package/dist/types/clients/workspaces-client.d.ts +152 -0
  93. package/dist/types/comms-api.d.ts +62 -0
  94. package/dist/types/consts/endpoints.d.ts +24 -0
  95. package/dist/types/index.d.ts +18 -0
  96. package/dist/types/testUtils/msw-handlers.d.ts +28 -0
  97. package/dist/types/testUtils/msw-setup.d.ts +1 -0
  98. package/dist/types/testUtils/obsidian-fetch-adapter.d.ts +29 -0
  99. package/dist/types/testUtils/test-defaults.d.ts +17 -0
  100. package/dist/types/transport/fetch-with-retry.d.ts +4 -0
  101. package/dist/types/transport/http-client.d.ts +13 -0
  102. package/dist/types/transport/http-dispatcher.d.ts +10 -0
  103. package/dist/types/types/api-version.d.ts +6 -0
  104. package/dist/types/types/entities.d.ts +1288 -0
  105. package/dist/types/types/enums.d.ts +55 -0
  106. package/dist/types/types/errors.d.ts +6 -0
  107. package/dist/types/types/http.d.ts +54 -0
  108. package/dist/types/types/index.d.ts +6 -0
  109. package/dist/types/types/requests.d.ts +366 -0
  110. package/dist/types/utils/case-conversion.d.ts +8 -0
  111. package/dist/types/utils/index.d.ts +3 -0
  112. package/dist/types/utils/timestamp-conversion.d.ts +13 -0
  113. package/dist/types/utils/url-helpers.d.ts +88 -0
  114. package/dist/types/utils/uuidv7.d.ts +40 -0
  115. package/package.json +91 -8
@@ -0,0 +1,29 @@
1
+ import type { RequestUrlParam, RequestUrlResponse } from 'obsidian';
2
+ import type { CustomFetch } from '../types/http.js';
3
+ /**
4
+ * Creates a CustomFetch adapter for Obsidian's requestUrl API.
5
+ *
6
+ * This adapter bridges the gap between Obsidian's requestUrl interface and the
7
+ * standard fetch-like interface expected by the Comms API SDK.
8
+ *
9
+ * Key differences handled by this adapter:
10
+ * - Obsidian returns response data as properties (response.json, response.text)
11
+ * while the SDK expects methods (response.json(), response.text())
12
+ * - Obsidian's requestUrl bypasses CORS restrictions that would block standard fetch
13
+ * - Obsidian throws on HTTP errors by default; we set throw: false to handle manually
14
+ * - Obsidian doesn't provide statusText; we default to empty string
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { requestUrl } from 'obsidian'
19
+ * import { createObsidianFetchAdapter } from './obsidian-fetch-adapter.js'
20
+ *
21
+ * const api = new CommsApi('your-token', {
22
+ * customFetch: createObsidianFetchAdapter(requestUrl)
23
+ * })
24
+ * ```
25
+ *
26
+ * @param requestUrl - The Obsidian requestUrl function
27
+ * @returns A CustomFetch function compatible with the Comms API SDK
28
+ */
29
+ export declare function createObsidianFetchAdapter(requestUrl: (request: RequestUrlParam | string) => Promise<RequestUrlResponse>): CustomFetch;
@@ -0,0 +1,17 @@
1
+ import type { Channel, Comment, Conversation, Group, Thread, User, Workspace, WorkspaceUser } from '../types/entities.js';
2
+ export declare const TEST_API_TOKEN = "test-api-token";
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";
6
+ export declare const TEST_COMMENT_ID = "7YpL3oZ4kZ9vP7Q1tR2sX41";
7
+ export declare const TEST_CONVERSATION_ID = "7YpL3oZ4kZ9vP7Q1tR2sX42";
8
+ export declare const TEST_MESSAGE_ID = "7YpL3oZ4kZ9vP7Q1tR2sX43";
9
+ export declare const TEST_GROUP_ID = "7YpL3oZ4kZ9vP7Q1tR2sX44";
10
+ export declare const mockUser: User;
11
+ export declare const mockWorkspace: Workspace;
12
+ export declare const mockChannel: Channel;
13
+ export declare const mockThread: Thread;
14
+ export declare const mockGroup: Group;
15
+ export declare const mockConversation: Conversation;
16
+ export declare const mockComment: Comment;
17
+ export declare const mockWorkspaceUser: WorkspaceUser;
@@ -0,0 +1,4 @@
1
+ import type { CustomFetch, HttpResponse } from '../types/http.js';
2
+ export declare function fetchWithRetry<T>(url: string, options: RequestInit & {
3
+ timeout?: number;
4
+ }, maxRetries?: number, customFetch?: CustomFetch): Promise<HttpResponse<T>>;
@@ -0,0 +1,13 @@
1
+ import type { CustomFetch, HttpMethod, HttpResponse } from '../types/http.js';
2
+ export declare function paramsSerializer(params: Record<string, unknown>): string;
3
+ export type RequestArgs = {
4
+ httpMethod: HttpMethod;
5
+ baseUri: string;
6
+ relativePath: string;
7
+ apiToken?: string;
8
+ payload?: Record<string, unknown>;
9
+ requestId?: string;
10
+ customFetch?: CustomFetch;
11
+ };
12
+ export declare function request<T>(args: RequestArgs): Promise<HttpResponse<T>>;
13
+ export declare function isSuccess(response: HttpResponse): boolean;
@@ -0,0 +1,10 @@
1
+ import type { Dispatcher } from 'undici';
2
+ export declare function getDefaultDispatcher(): Promise<Dispatcher | undefined>;
3
+ /**
4
+ * Drains the default dispatcher's connection pool. CLIs and scripts should
5
+ * `await` this before exit so Node's event loop empties immediately instead
6
+ * of waiting ~4s on keep-alive. No-op in the browser branch.
7
+ */
8
+ export declare function closeDefaultDispatcher(): Promise<void>;
9
+ export declare function resetDefaultDispatcherForTests(): void;
10
+ export declare function suppressExperimentalWarningsSync<T>(fn: () => T): T;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Supported Comms API versions
3
+ */
4
+ export declare const API_VERSIONS: readonly ["v1"];
5
+ export type ApiVersion = (typeof API_VERSIONS)[number];
6
+ export declare const DEFAULT_API_VERSION: ApiVersion;