@doist/twist-sdk 0.1.0-alpha.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.
- package/LICENSE +21 -0
- package/README.md +222 -0
- package/dist/authentication.d.ts +79 -0
- package/dist/authentication.d.ts.map +1 -0
- package/dist/authentication.js +115 -0
- package/dist/authentication.test.d.ts.map +1 -0
- package/dist/batch-builder.d.ts +27 -0
- package/dist/batch-builder.d.ts.map +1 -0
- package/dist/batch-builder.js +191 -0
- package/dist/batch-builder.test.d.ts.map +1 -0
- package/dist/clients/channels-client.d.ts +215 -0
- package/dist/clients/channels-client.d.ts.map +1 -0
- package/dist/clients/channels-client.js +140 -0
- package/dist/clients/channels-client.test.d.ts.map +1 -0
- package/dist/clients/comments-client.d.ts +125 -0
- package/dist/clients/comments-client.d.ts.map +1 -0
- package/dist/clients/comments-client.js +86 -0
- package/dist/clients/comments-client.test.d.ts.map +1 -0
- package/dist/clients/conversation-messages-client.d.ts +141 -0
- package/dist/clients/conversation-messages-client.d.ts.map +1 -0
- package/dist/clients/conversation-messages-client.js +92 -0
- package/dist/clients/conversation-messages-client.test.d.ts.map +1 -0
- package/dist/clients/conversations-client.d.ts +263 -0
- package/dist/clients/conversations-client.d.ts.map +1 -0
- package/dist/clients/conversations-client.js +174 -0
- package/dist/clients/conversations-client.test.d.ts.map +1 -0
- package/dist/clients/groups-client.d.ts +175 -0
- package/dist/clients/groups-client.d.ts.map +1 -0
- package/dist/clients/groups-client.js +104 -0
- package/dist/clients/groups-client.test.d.ts.map +1 -0
- package/dist/clients/inbox-client.d.ts +146 -0
- package/dist/clients/inbox-client.d.ts.map +1 -0
- package/dist/clients/inbox-client.js +92 -0
- package/dist/clients/reactions-client.d.ts +98 -0
- package/dist/clients/reactions-client.d.ts.map +1 -0
- package/dist/clients/reactions-client.js +86 -0
- package/dist/clients/reactions-client.test.d.ts.map +1 -0
- package/dist/clients/search-client.d.ts +128 -0
- package/dist/clients/search-client.d.ts.map +1 -0
- package/dist/clients/search-client.js +89 -0
- package/dist/clients/threads-client.d.ts +321 -0
- package/dist/clients/threads-client.d.ts.map +1 -0
- package/dist/clients/threads-client.js +212 -0
- package/dist/clients/threads-client.test.d.ts.map +1 -0
- package/dist/clients/users-client.d.ts +254 -0
- package/dist/clients/users-client.d.ts.map +1 -0
- package/dist/clients/users-client.js +155 -0
- package/dist/clients/users-client.test.d.ts.map +1 -0
- package/dist/clients/workspace-users-client.d.ts +220 -0
- package/dist/clients/workspace-users-client.d.ts.map +1 -0
- package/dist/clients/workspace-users-client.js +132 -0
- package/dist/clients/workspace-users-client.test.d.ts.map +1 -0
- package/dist/clients/workspaces-client.d.ts +143 -0
- package/dist/clients/workspaces-client.d.ts.map +1 -0
- package/dist/clients/workspaces-client.js +89 -0
- package/dist/clients/workspaces-client.test.d.ts.map +1 -0
- package/dist/consts/endpoints.d.ts +16 -0
- package/dist/consts/endpoints.d.ts.map +1 -0
- package/dist/consts/endpoints.js +23 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/rest-client.d.ts +5 -0
- package/dist/rest-client.d.ts.map +1 -0
- package/dist/rest-client.js +201 -0
- package/dist/rest-client.test.d.ts.map +1 -0
- package/dist/testUtils/msw-handlers.d.ts +29 -0
- package/dist/testUtils/msw-handlers.d.ts.map +1 -0
- package/dist/testUtils/msw-handlers.js +52 -0
- package/dist/testUtils/msw-setup.d.ts +2 -0
- package/dist/testUtils/msw-setup.d.ts.map +1 -0
- package/dist/testUtils/msw-setup.js +21 -0
- package/dist/testUtils/test-defaults.d.ts +11 -0
- package/dist/testUtils/test-defaults.d.ts.map +1 -0
- package/dist/testUtils/test-defaults.js +96 -0
- package/dist/twist-api.d.ts +64 -0
- package/dist/twist-api.d.ts.map +1 -0
- package/dist/twist-api.js +76 -0
- package/dist/twist-api.test.d.ts.map +1 -0
- package/dist/types/batch.d.ts +36 -0
- package/dist/types/batch.d.ts.map +1 -0
- package/dist/types/batch.js +2 -0
- package/dist/types/entities.d.ts +367 -0
- package/dist/types/entities.d.ts.map +1 -0
- package/dist/types/entities.js +358 -0
- package/dist/types/enums.d.ts +22 -0
- package/dist/types/enums.d.ts.map +1 -0
- package/dist/types/enums.js +7 -0
- package/dist/types/errors.d.ts +7 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +30 -0
- package/dist/types/http.d.ts +12 -0
- package/dist/types/http.d.ts.map +1 -0
- package/dist/types/http.js +2 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +22 -0
- package/dist/types/requests.d.ts +97 -0
- package/dist/types/requests.d.ts.map +1 -0
- package/dist/types/requests.js +92 -0
- package/dist/utils/case-conversion.d.ts +9 -0
- package/dist/utils/case-conversion.d.ts.map +1 -0
- package/dist/utils/case-conversion.js +56 -0
- package/dist/utils/case-conversion.test.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +18 -0
- package/dist/utils/timestamp-conversion.d.ts +14 -0
- package/dist/utils/timestamp-conversion.d.ts.map +1 -0
- package/dist/utils/timestamp-conversion.js +47 -0
- package/dist/utils/url-helpers.d.ts +154 -0
- package/dist/utils/url-helpers.d.ts.map +1 -0
- package/dist/utils/url-helpers.js +223 -0
- package/dist/utils/url-helpers.test.d.ts.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InboxClient = void 0;
|
|
4
|
+
var endpoints_1 = require("../consts/endpoints");
|
|
5
|
+
var rest_client_1 = require("../rest-client");
|
|
6
|
+
var entities_1 = require("../types/entities");
|
|
7
|
+
/**
|
|
8
|
+
* Client for interacting with Twist inbox endpoints.
|
|
9
|
+
*/
|
|
10
|
+
var InboxClient = /** @class */ (function () {
|
|
11
|
+
function InboxClient(apiToken, baseUrl) {
|
|
12
|
+
this.apiToken = apiToken;
|
|
13
|
+
this.baseUrl = baseUrl;
|
|
14
|
+
}
|
|
15
|
+
InboxClient.prototype.getBaseUri = function () {
|
|
16
|
+
return this.baseUrl ? "".concat(this.baseUrl, "/api/v3") : (0, endpoints_1.getTwistBaseUri)();
|
|
17
|
+
};
|
|
18
|
+
InboxClient.prototype.getInbox = function (args, options) {
|
|
19
|
+
var params = {
|
|
20
|
+
workspace_id: args.workspaceId,
|
|
21
|
+
};
|
|
22
|
+
if (args.since)
|
|
23
|
+
params.since_ts_or_obj_idx = Math.floor(args.since.getTime() / 1000);
|
|
24
|
+
if (args.until)
|
|
25
|
+
params.until_ts_or_obj_idx = Math.floor(args.until.getTime() / 1000);
|
|
26
|
+
if (args.limit)
|
|
27
|
+
params.limit = args.limit;
|
|
28
|
+
if (args.cursor)
|
|
29
|
+
params.cursor = args.cursor;
|
|
30
|
+
var method = 'GET';
|
|
31
|
+
var url = "".concat(endpoints_1.ENDPOINT_INBOX, "/get");
|
|
32
|
+
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
33
|
+
return { method: method, url: url, params: params };
|
|
34
|
+
}
|
|
35
|
+
return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return response.data.map(function (thread) { return entities_1.InboxThreadSchema.parse(thread); }); });
|
|
36
|
+
};
|
|
37
|
+
InboxClient.prototype.getCount = function (workspaceId, options) {
|
|
38
|
+
var method = 'GET';
|
|
39
|
+
var url = "".concat(endpoints_1.ENDPOINT_INBOX, "/get_count");
|
|
40
|
+
var params = { workspace_id: workspaceId };
|
|
41
|
+
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
42
|
+
return { method: method, url: url, params: params };
|
|
43
|
+
}
|
|
44
|
+
return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return response.data.data; });
|
|
45
|
+
};
|
|
46
|
+
InboxClient.prototype.archiveThread = function (id, options) {
|
|
47
|
+
var method = 'POST';
|
|
48
|
+
var url = "".concat(endpoints_1.ENDPOINT_INBOX, "/archive");
|
|
49
|
+
var params = { id: id };
|
|
50
|
+
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
51
|
+
return { method: method, url: url, params: params };
|
|
52
|
+
}
|
|
53
|
+
return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function () { return undefined; });
|
|
54
|
+
};
|
|
55
|
+
InboxClient.prototype.unarchiveThread = function (id, options) {
|
|
56
|
+
var method = 'POST';
|
|
57
|
+
var url = "".concat(endpoints_1.ENDPOINT_INBOX, "/unarchive");
|
|
58
|
+
var params = { id: id };
|
|
59
|
+
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
60
|
+
return { method: method, url: url, params: params };
|
|
61
|
+
}
|
|
62
|
+
return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function () { return undefined; });
|
|
63
|
+
};
|
|
64
|
+
InboxClient.prototype.markAllRead = function (workspaceId, options) {
|
|
65
|
+
var method = 'POST';
|
|
66
|
+
var url = "".concat(endpoints_1.ENDPOINT_INBOX, "/mark_all_read");
|
|
67
|
+
var params = { workspace_id: workspaceId };
|
|
68
|
+
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
69
|
+
return { method: method, url: url, params: params };
|
|
70
|
+
}
|
|
71
|
+
return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function () { return undefined; });
|
|
72
|
+
};
|
|
73
|
+
InboxClient.prototype.archiveAll = function (args, options) {
|
|
74
|
+
var params = {
|
|
75
|
+
workspace_id: args.workspaceId,
|
|
76
|
+
};
|
|
77
|
+
if (args.channelIds)
|
|
78
|
+
params.channel_ids = args.channelIds;
|
|
79
|
+
if (args.since)
|
|
80
|
+
params.since_ts_or_obj_idx = Math.floor(args.since.getTime() / 1000);
|
|
81
|
+
if (args.until)
|
|
82
|
+
params.until_ts_or_obj_idx = Math.floor(args.until.getTime() / 1000);
|
|
83
|
+
var method = 'POST';
|
|
84
|
+
var url = "".concat(endpoints_1.ENDPOINT_INBOX, "/archive_all");
|
|
85
|
+
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
86
|
+
return { method: method, url: url, params: params };
|
|
87
|
+
}
|
|
88
|
+
return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function () { return undefined; });
|
|
89
|
+
};
|
|
90
|
+
return InboxClient;
|
|
91
|
+
}());
|
|
92
|
+
exports.InboxClient = InboxClient;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { BatchRequestDescriptor } from '../types/batch';
|
|
2
|
+
type AddReactionArgs = {
|
|
3
|
+
threadId?: number;
|
|
4
|
+
commentId?: number;
|
|
5
|
+
messageId?: number;
|
|
6
|
+
reaction: string;
|
|
7
|
+
};
|
|
8
|
+
type RemoveReactionArgs = {
|
|
9
|
+
threadId?: number;
|
|
10
|
+
commentId?: number;
|
|
11
|
+
messageId?: number;
|
|
12
|
+
reaction: string;
|
|
13
|
+
};
|
|
14
|
+
type GetReactionsArgs = {
|
|
15
|
+
threadId?: number;
|
|
16
|
+
commentId?: number;
|
|
17
|
+
messageId?: number;
|
|
18
|
+
};
|
|
19
|
+
type ReactionObject = Record<string, number[]> | null;
|
|
20
|
+
/**
|
|
21
|
+
* Client for interacting with Twist reaction endpoints.
|
|
22
|
+
*/
|
|
23
|
+
export declare class ReactionsClient {
|
|
24
|
+
private apiToken;
|
|
25
|
+
private baseUrl?;
|
|
26
|
+
constructor(apiToken: string, baseUrl?: string | undefined);
|
|
27
|
+
private getBaseUri;
|
|
28
|
+
/**
|
|
29
|
+
* Adds an emoji reaction to a thread, comment, or conversation message.
|
|
30
|
+
*
|
|
31
|
+
* @param args - The arguments for adding a reaction.
|
|
32
|
+
* @param args.threadId - Optional thread ID.
|
|
33
|
+
* @param args.commentId - Optional comment ID.
|
|
34
|
+
* @param args.messageId - Optional message ID (for conversation messages).
|
|
35
|
+
* @param args.reaction - The reaction emoji to add.
|
|
36
|
+
* @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* await api.reactions.add({ threadId: 789, reaction: '👍' })
|
|
41
|
+
*
|
|
42
|
+
* // Batch usage
|
|
43
|
+
* const batch = api.createBatch()
|
|
44
|
+
* batch.add(() => api.reactions.add({ threadId: 789, reaction: '👍' }, { batch: true }))
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
add(args: AddReactionArgs, options: {
|
|
48
|
+
batch: true;
|
|
49
|
+
}): BatchRequestDescriptor<void>;
|
|
50
|
+
add(args: AddReactionArgs, options?: {
|
|
51
|
+
batch?: false;
|
|
52
|
+
}): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Gets reactions for a thread, comment, or conversation message.
|
|
55
|
+
*
|
|
56
|
+
* @param args - The arguments for getting reactions.
|
|
57
|
+
* @param args.threadId - Optional thread ID.
|
|
58
|
+
* @param args.commentId - Optional comment ID.
|
|
59
|
+
* @param args.messageId - Optional message ID (for conversation messages).
|
|
60
|
+
* @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
|
|
61
|
+
* @returns A reaction object with emoji reactions as keys and arrays of user IDs as values, or null if no reactions.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const reactions = await api.reactions.get({ threadId: 789 })
|
|
66
|
+
* // Returns: { "👍": [1, 2, 3], "❤️": [4, 5] }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
get(args: GetReactionsArgs, options: {
|
|
70
|
+
batch: true;
|
|
71
|
+
}): BatchRequestDescriptor<ReactionObject>;
|
|
72
|
+
get(args: GetReactionsArgs, options?: {
|
|
73
|
+
batch?: false;
|
|
74
|
+
}): Promise<ReactionObject>;
|
|
75
|
+
/**
|
|
76
|
+
* Removes an emoji reaction from a thread, comment, or conversation message.
|
|
77
|
+
*
|
|
78
|
+
* @param args - The arguments for removing a reaction.
|
|
79
|
+
* @param args.threadId - Optional thread ID.
|
|
80
|
+
* @param args.commentId - Optional comment ID.
|
|
81
|
+
* @param args.messageId - Optional message ID (for conversation messages).
|
|
82
|
+
* @param args.reaction - The reaction emoji to remove.
|
|
83
|
+
* @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* await api.reactions.remove({ threadId: 789, reaction: '👍' })
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
remove(args: RemoveReactionArgs, options: {
|
|
91
|
+
batch: true;
|
|
92
|
+
}): BatchRequestDescriptor<void>;
|
|
93
|
+
remove(args: RemoveReactionArgs, options?: {
|
|
94
|
+
batch?: false;
|
|
95
|
+
}): Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
export {};
|
|
98
|
+
//# sourceMappingURL=reactions-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactions-client.d.ts","sourceRoot":"","sources":["../../src/clients/reactions-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAE5D,KAAK,eAAe,GAAG;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,KAAK,kBAAkB,GAAG;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,KAAK,gBAAgB,GAAG;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IACl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2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReactionsClient = void 0;
|
|
4
|
+
var endpoints_1 = require("../consts/endpoints");
|
|
5
|
+
var rest_client_1 = require("../rest-client");
|
|
6
|
+
/**
|
|
7
|
+
* Client for interacting with Twist reaction endpoints.
|
|
8
|
+
*/
|
|
9
|
+
var ReactionsClient = /** @class */ (function () {
|
|
10
|
+
function ReactionsClient(apiToken, baseUrl) {
|
|
11
|
+
this.apiToken = apiToken;
|
|
12
|
+
this.baseUrl = baseUrl;
|
|
13
|
+
}
|
|
14
|
+
ReactionsClient.prototype.getBaseUri = function () {
|
|
15
|
+
return this.baseUrl ? "".concat(this.baseUrl, "/api/v3") : (0, endpoints_1.getTwistBaseUri)();
|
|
16
|
+
};
|
|
17
|
+
ReactionsClient.prototype.add = function (args, options) {
|
|
18
|
+
var params = {
|
|
19
|
+
reaction: args.reaction,
|
|
20
|
+
};
|
|
21
|
+
if (args.threadId) {
|
|
22
|
+
params.thread_id = args.threadId;
|
|
23
|
+
}
|
|
24
|
+
else if (args.commentId) {
|
|
25
|
+
params.comment_id = args.commentId;
|
|
26
|
+
}
|
|
27
|
+
else if (args.messageId) {
|
|
28
|
+
params.message_id = args.messageId;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
throw new Error('Must provide one of: threadId, commentId, or messageId');
|
|
32
|
+
}
|
|
33
|
+
var method = 'POST';
|
|
34
|
+
var url = "".concat(endpoints_1.ENDPOINT_REACTIONS, "/add");
|
|
35
|
+
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
36
|
+
return { method: method, url: url, params: params };
|
|
37
|
+
}
|
|
38
|
+
return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function () { return undefined; });
|
|
39
|
+
};
|
|
40
|
+
ReactionsClient.prototype.get = function (args, options) {
|
|
41
|
+
var params = {};
|
|
42
|
+
if (args.threadId) {
|
|
43
|
+
params.thread_id = args.threadId;
|
|
44
|
+
}
|
|
45
|
+
else if (args.commentId) {
|
|
46
|
+
params.comment_id = args.commentId;
|
|
47
|
+
}
|
|
48
|
+
else if (args.messageId) {
|
|
49
|
+
params.message_id = args.messageId;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new Error('Must provide one of: threadId, commentId, or messageId');
|
|
53
|
+
}
|
|
54
|
+
var method = 'POST';
|
|
55
|
+
var url = "".concat(endpoints_1.ENDPOINT_REACTIONS, "/get");
|
|
56
|
+
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
57
|
+
return { method: method, url: url, params: params };
|
|
58
|
+
}
|
|
59
|
+
return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return response.data; });
|
|
60
|
+
};
|
|
61
|
+
ReactionsClient.prototype.remove = function (args, options) {
|
|
62
|
+
var params = {
|
|
63
|
+
reaction: args.reaction,
|
|
64
|
+
};
|
|
65
|
+
if (args.threadId) {
|
|
66
|
+
params.thread_id = args.threadId;
|
|
67
|
+
}
|
|
68
|
+
else if (args.commentId) {
|
|
69
|
+
params.comment_id = args.commentId;
|
|
70
|
+
}
|
|
71
|
+
else if (args.messageId) {
|
|
72
|
+
params.message_id = args.messageId;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
throw new Error('Must provide one of: threadId, commentId, or messageId');
|
|
76
|
+
}
|
|
77
|
+
var method = 'POST';
|
|
78
|
+
var url = "".concat(endpoints_1.ENDPOINT_REACTIONS, "/remove");
|
|
79
|
+
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
80
|
+
return { method: method, url: url, params: params };
|
|
81
|
+
}
|
|
82
|
+
return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function () { return undefined; });
|
|
83
|
+
};
|
|
84
|
+
return ReactionsClient;
|
|
85
|
+
}());
|
|
86
|
+
exports.ReactionsClient = ReactionsClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactions-client.test.d.ts","sourceRoot":"","sources":["../../src/clients/reactions-client.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { BatchRequestDescriptor } from '../types/batch';
|
|
2
|
+
import { SearchResult } from '../types/entities';
|
|
3
|
+
type SearchArgs = {
|
|
4
|
+
query: string;
|
|
5
|
+
workspaceId: number;
|
|
6
|
+
channelIds?: number[];
|
|
7
|
+
authorIds?: number[];
|
|
8
|
+
mentionSelf?: boolean;
|
|
9
|
+
dateFrom?: string;
|
|
10
|
+
dateTo?: string;
|
|
11
|
+
limit?: number;
|
|
12
|
+
cursor?: string;
|
|
13
|
+
};
|
|
14
|
+
type SearchThreadArgs = {
|
|
15
|
+
query: string;
|
|
16
|
+
threadId: number;
|
|
17
|
+
limit?: number;
|
|
18
|
+
cursor?: string;
|
|
19
|
+
};
|
|
20
|
+
type SearchConversationArgs = {
|
|
21
|
+
query: string;
|
|
22
|
+
conversationId: number;
|
|
23
|
+
limit?: number;
|
|
24
|
+
cursor?: string;
|
|
25
|
+
};
|
|
26
|
+
type SearchResponse = {
|
|
27
|
+
items: SearchResult[];
|
|
28
|
+
nextCursorMark?: string;
|
|
29
|
+
hasMore: boolean;
|
|
30
|
+
isPlanRestricted: boolean;
|
|
31
|
+
};
|
|
32
|
+
type SearchThreadResponse = {
|
|
33
|
+
commentIds: number[];
|
|
34
|
+
};
|
|
35
|
+
type SearchConversationResponse = {
|
|
36
|
+
messageIds: number[];
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Client for interacting with Twist search endpoints.
|
|
40
|
+
*/
|
|
41
|
+
export declare class SearchClient {
|
|
42
|
+
private apiToken;
|
|
43
|
+
private baseUrl?;
|
|
44
|
+
constructor(apiToken: string, baseUrl?: string | undefined);
|
|
45
|
+
private getBaseUri;
|
|
46
|
+
/**
|
|
47
|
+
* Searches across all threads and conversations in a workspace.
|
|
48
|
+
*
|
|
49
|
+
* @param args - The arguments for searching.
|
|
50
|
+
* @param args.query - The search query string.
|
|
51
|
+
* @param args.workspaceId - The workspace ID to search in.
|
|
52
|
+
* @param args.channelIds - Optional array of channel IDs to filter by.
|
|
53
|
+
* @param args.authorIds - Optional array of author user IDs to filter by.
|
|
54
|
+
* @param args.mentionSelf - Optional flag to filter by mentions of the current user.
|
|
55
|
+
* @param args.dateFrom - Optional start date for filtering (YYYY-MM-DD).
|
|
56
|
+
* @param args.dateTo - Optional end date for filtering (YYYY-MM-DD).
|
|
57
|
+
* @param args.limit - Optional limit on number of results returned.
|
|
58
|
+
* @param args.cursor - Optional cursor for pagination.
|
|
59
|
+
* @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
|
|
60
|
+
* @returns Search results with pagination.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const results = await api.search.search({
|
|
65
|
+
* query: 'important meeting',
|
|
66
|
+
* workspaceId: 123
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
search(args: SearchArgs, options: {
|
|
71
|
+
batch: true;
|
|
72
|
+
}): BatchRequestDescriptor<SearchResponse>;
|
|
73
|
+
search(args: SearchArgs, options?: {
|
|
74
|
+
batch?: false;
|
|
75
|
+
}): Promise<SearchResponse>;
|
|
76
|
+
/**
|
|
77
|
+
* Searches within comments of a specific thread.
|
|
78
|
+
*
|
|
79
|
+
* @param args - The arguments for searching within a thread.
|
|
80
|
+
* @param args.query - The search query string.
|
|
81
|
+
* @param args.threadId - The thread ID to search in.
|
|
82
|
+
* @param args.limit - Optional limit on number of results returned.
|
|
83
|
+
* @param args.cursor - Optional cursor for pagination.
|
|
84
|
+
* @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
|
|
85
|
+
* @returns Comment IDs that match the search query.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const results = await api.search.searchThread({
|
|
90
|
+
* query: 'deadline',
|
|
91
|
+
* threadId: 789
|
|
92
|
+
* })
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
searchThread(args: SearchThreadArgs, options: {
|
|
96
|
+
batch: true;
|
|
97
|
+
}): BatchRequestDescriptor<SearchThreadResponse>;
|
|
98
|
+
searchThread(args: SearchThreadArgs, options?: {
|
|
99
|
+
batch?: false;
|
|
100
|
+
}): Promise<SearchThreadResponse>;
|
|
101
|
+
/**
|
|
102
|
+
* Searches within messages of a specific conversation.
|
|
103
|
+
*
|
|
104
|
+
* @param args - The arguments for searching within a conversation.
|
|
105
|
+
* @param args.query - The search query string.
|
|
106
|
+
* @param args.conversationId - The conversation ID to search in.
|
|
107
|
+
* @param args.limit - Optional limit on number of results returned.
|
|
108
|
+
* @param args.cursor - Optional cursor for pagination.
|
|
109
|
+
* @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
|
|
110
|
+
* @returns Message IDs that match the search query.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const results = await api.search.searchConversation({
|
|
115
|
+
* query: 'budget',
|
|
116
|
+
* conversationId: 456
|
|
117
|
+
* })
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
searchConversation(args: SearchConversationArgs, options: {
|
|
121
|
+
batch: true;
|
|
122
|
+
}): BatchRequestDescriptor<SearchConversationResponse>;
|
|
123
|
+
searchConversation(args: SearchConversationArgs, options?: {
|
|
124
|
+
batch?: false;
|
|
125
|
+
}): Promise<SearchConversationResponse>;
|
|
126
|
+
}
|
|
127
|
+
export {};
|
|
128
|
+
//# sourceMappingURL=search-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-client.d.ts","sourceRoot":"","sources":["../../src/clients/search-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAsB,MAAM,mBAAmB,CAAA;AAEpE,KAAK,UAAU,G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AAE,UAAU,EAAE,OAAO,EAAE;QAAE,KAAK,EAAE,IAAI,CAAA;KAAE,GAAG,sBAAsB,CAAC,cAAc,CAAC;IAC1F,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAiC9E;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAAY,CACR,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE;QAAE,KAAK,EAAE,IAAI,CAAA;KAAE,GACzB,sBAAsB,CAAC,oBAAoB,CAAC;IAC/C,YAAY,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA6BhG;;;;;;;;;;;;;;;;;;OAkBG;IACH,kBAAkB,CACd,IAAI,EAAE,sBAAsB,EAC5B,OAAO,EAAE;QAAE,KAAK,EAAE,IAAI,CAAA;KAAE,GACzB,sBAAsB,CAAC,0BAA0B,CAAC;IACrD,kBAAkB,CACd,IAAI,EAAE,sBAAsB,EAC5B,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE,GAC5B,OAAO,CAAC,0BAA0B,CAAC;CA4BzC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.SearchClient = void 0;
|
|
15
|
+
var endpoints_1 = require("../consts/endpoints");
|
|
16
|
+
var rest_client_1 = require("../rest-client");
|
|
17
|
+
var entities_1 = require("../types/entities");
|
|
18
|
+
/**
|
|
19
|
+
* Client for interacting with Twist search endpoints.
|
|
20
|
+
*/
|
|
21
|
+
var SearchClient = /** @class */ (function () {
|
|
22
|
+
function SearchClient(apiToken, baseUrl) {
|
|
23
|
+
this.apiToken = apiToken;
|
|
24
|
+
this.baseUrl = baseUrl;
|
|
25
|
+
}
|
|
26
|
+
SearchClient.prototype.getBaseUri = function () {
|
|
27
|
+
return this.baseUrl ? "".concat(this.baseUrl, "/api/v3") : (0, endpoints_1.getTwistBaseUri)();
|
|
28
|
+
};
|
|
29
|
+
SearchClient.prototype.search = function (args, options) {
|
|
30
|
+
var params = {
|
|
31
|
+
query: args.query,
|
|
32
|
+
workspace_id: args.workspaceId,
|
|
33
|
+
};
|
|
34
|
+
if (args.channelIds)
|
|
35
|
+
params.channel_ids = args.channelIds;
|
|
36
|
+
if (args.authorIds)
|
|
37
|
+
params.author_ids = args.authorIds;
|
|
38
|
+
if (args.mentionSelf !== undefined)
|
|
39
|
+
params.mention_self = args.mentionSelf;
|
|
40
|
+
if (args.dateFrom)
|
|
41
|
+
params.date_from = args.dateFrom;
|
|
42
|
+
if (args.dateTo)
|
|
43
|
+
params.date_to = args.dateTo;
|
|
44
|
+
if (args.limit)
|
|
45
|
+
params.limit = args.limit;
|
|
46
|
+
if (args.cursor)
|
|
47
|
+
params.cursor = args.cursor;
|
|
48
|
+
var method = 'GET';
|
|
49
|
+
var url = endpoints_1.ENDPOINT_SEARCH;
|
|
50
|
+
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
51
|
+
return { method: method, url: url, params: params };
|
|
52
|
+
}
|
|
53
|
+
return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return (__assign(__assign({}, response.data), { items: response.data.items.map(function (result) { return entities_1.SearchResultSchema.parse(result); }) })); });
|
|
54
|
+
};
|
|
55
|
+
SearchClient.prototype.searchThread = function (args, options) {
|
|
56
|
+
var params = {
|
|
57
|
+
query: args.query,
|
|
58
|
+
thread_id: args.threadId,
|
|
59
|
+
};
|
|
60
|
+
if (args.limit)
|
|
61
|
+
params.limit = args.limit;
|
|
62
|
+
if (args.cursor)
|
|
63
|
+
params.cursor = args.cursor;
|
|
64
|
+
var method = 'GET';
|
|
65
|
+
var url = "".concat(endpoints_1.ENDPOINT_SEARCH, "/thread");
|
|
66
|
+
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
67
|
+
return { method: method, url: url, params: params };
|
|
68
|
+
}
|
|
69
|
+
return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return response.data; });
|
|
70
|
+
};
|
|
71
|
+
SearchClient.prototype.searchConversation = function (args, options) {
|
|
72
|
+
var params = {
|
|
73
|
+
query: args.query,
|
|
74
|
+
conversation_id: args.conversationId,
|
|
75
|
+
};
|
|
76
|
+
if (args.limit)
|
|
77
|
+
params.limit = args.limit;
|
|
78
|
+
if (args.cursor)
|
|
79
|
+
params.cursor = args.cursor;
|
|
80
|
+
var method = 'GET';
|
|
81
|
+
var url = "".concat(endpoints_1.ENDPOINT_SEARCH, "/conversation");
|
|
82
|
+
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
83
|
+
return { method: method, url: url, params: params };
|
|
84
|
+
}
|
|
85
|
+
return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return response.data; });
|
|
86
|
+
};
|
|
87
|
+
return SearchClient;
|
|
88
|
+
}());
|
|
89
|
+
exports.SearchClient = SearchClient;
|