@doist/twist-sdk 2.1.0 → 2.1.2
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/dist/cjs/batch-builder.js +9 -8
- package/dist/cjs/clients/comments-client.js +4 -3
- package/dist/cjs/types/entities.js +3 -2
- package/dist/esm/batch-builder.js +9 -8
- package/dist/esm/clients/comments-client.js +4 -3
- package/dist/esm/types/entities.js +2 -1
- package/dist/types/types/entities.d.ts +3 -0
- package/package.json +1 -1
|
@@ -61,6 +61,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
61
61
|
};
|
|
62
62
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
63
|
exports.BatchBuilder = void 0;
|
|
64
|
+
var zod_1 = require("zod");
|
|
64
65
|
var base_client_1 = require("./clients/base-client");
|
|
65
66
|
var rest_client_1 = require("./rest-client");
|
|
66
67
|
var case_conversion_1 = require("./utils/case-conversion");
|
|
@@ -201,13 +202,7 @@ var BatchBuilder = /** @class */ (function (_super) {
|
|
|
201
202
|
// Validate with schema if provided
|
|
202
203
|
var finalData = transformed;
|
|
203
204
|
if (descriptor.schema && apiResponse.code >= 200 && apiResponse.code < 300) {
|
|
204
|
-
|
|
205
|
-
finalData = descriptor.schema.parse(transformed);
|
|
206
|
-
}
|
|
207
|
-
catch (error) {
|
|
208
|
-
// If validation fails, include the error in the response
|
|
209
|
-
console.error('Batch response validation failed:', error);
|
|
210
|
-
}
|
|
205
|
+
finalData = descriptor.schema.parse(transformed);
|
|
211
206
|
}
|
|
212
207
|
// Parse headers string into object
|
|
213
208
|
var headers = {};
|
|
@@ -264,7 +259,13 @@ var BatchBuilder = /** @class */ (function (_super) {
|
|
|
264
259
|
chunks = this.chunkRequests(__spreadArray([], requests, true), BatchBuilder.CHUNK_SIZE);
|
|
265
260
|
chunkPromises = chunks.map(function (chunk) {
|
|
266
261
|
return _this.executeSingleBatch(chunk).catch(function (error) {
|
|
267
|
-
//
|
|
262
|
+
// Rethrow schema validation errors — they indicate a programming
|
|
263
|
+
// issue (wrong schema or unexpected API response shape) and should
|
|
264
|
+
// not be silently swallowed.
|
|
265
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
266
|
+
throw error;
|
|
267
|
+
}
|
|
268
|
+
// Collect network/request errors but don't fail fast - allow other chunks to complete
|
|
268
269
|
console.error('Batch chunk failed:', error);
|
|
269
270
|
// Return error responses for all requests in this chunk
|
|
270
271
|
return chunk.map(function () { return ({
|
|
@@ -55,9 +55,10 @@ var CommentsClient = /** @class */ (function (_super) {
|
|
|
55
55
|
var method = 'GET';
|
|
56
56
|
var url = "".concat(endpoints_1.ENDPOINT_COMMENTS, "/getone");
|
|
57
57
|
var params = { id: id };
|
|
58
|
-
|
|
58
|
+
// The API wraps the response in {"comment": {...}}, so we need to unwrap it
|
|
59
|
+
var wrappedSchema = zod_1.z.object({ comment: entities_1.CommentSchema }).transform(function (data) { return data.comment; });
|
|
59
60
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
60
|
-
return { method: method, url: url, params: params, schema:
|
|
61
|
+
return { method: method, url: url, params: params, schema: wrappedSchema };
|
|
61
62
|
}
|
|
62
63
|
return (0, rest_client_1.request)({
|
|
63
64
|
httpMethod: method,
|
|
@@ -66,7 +67,7 @@ var CommentsClient = /** @class */ (function (_super) {
|
|
|
66
67
|
apiToken: this.apiToken,
|
|
67
68
|
payload: params,
|
|
68
69
|
customFetch: this.customFetch,
|
|
69
|
-
}).then(function (response) { return
|
|
70
|
+
}).then(function (response) { return wrappedSchema.parse(response.data); });
|
|
70
71
|
};
|
|
71
72
|
CommentsClient.prototype.createComment = function (args, options) {
|
|
72
73
|
var method = 'POST';
|
|
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.SearchResultSchema = exports.UnreadConversationSchema = exports.UnreadThreadSchema = exports.InboxThreadSchema = exports.ConversationMessageSchema = exports.WorkspaceUserSchema = exports.CommentSchema = exports.ConversationSchema = exports.GroupSchema = exports.ThreadSchema = exports.ChannelSchema = exports.WorkspaceSchema = exports.UserSchema = exports.SystemMessageSchema = void 0;
|
|
14
|
+
exports.SearchResultSchema = exports.SEARCH_RESULT_TYPES = exports.UnreadConversationSchema = exports.UnreadThreadSchema = exports.InboxThreadSchema = exports.ConversationMessageSchema = exports.WorkspaceUserSchema = exports.CommentSchema = exports.ConversationSchema = exports.GroupSchema = exports.ThreadSchema = exports.ChannelSchema = exports.WorkspaceSchema = exports.UserSchema = exports.SystemMessageSchema = void 0;
|
|
15
15
|
var zod_1 = require("zod");
|
|
16
16
|
var url_helpers_1 = require("../utils/url-helpers");
|
|
17
17
|
var enums_1 = require("./enums");
|
|
@@ -356,9 +356,10 @@ exports.UnreadConversationSchema = zod_1.z.object({
|
|
|
356
356
|
directMention: zod_1.z.boolean(),
|
|
357
357
|
});
|
|
358
358
|
// SearchResult entity from API
|
|
359
|
+
exports.SEARCH_RESULT_TYPES = ['thread', 'comment', 'message', 'conversation'];
|
|
359
360
|
exports.SearchResultSchema = zod_1.z.object({
|
|
360
361
|
id: zod_1.z.string(),
|
|
361
|
-
type: zod_1.z.enum(
|
|
362
|
+
type: zod_1.z.enum(exports.SEARCH_RESULT_TYPES),
|
|
362
363
|
snippet: zod_1.z.string(),
|
|
363
364
|
snippetCreatorId: zod_1.z.number(),
|
|
364
365
|
snippetLastUpdated: zod_1.z.date(),
|
|
@@ -58,6 +58,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
58
58
|
}
|
|
59
59
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
60
60
|
};
|
|
61
|
+
import { z } from 'zod';
|
|
61
62
|
import { BaseClient } from './clients/base-client.js';
|
|
62
63
|
import { fetchWithRetry } from './rest-client.js';
|
|
63
64
|
import { camelCaseKeys, snakeCaseKeys } from './utils/case-conversion.js';
|
|
@@ -198,13 +199,7 @@ var BatchBuilder = /** @class */ (function (_super) {
|
|
|
198
199
|
// Validate with schema if provided
|
|
199
200
|
var finalData = transformed;
|
|
200
201
|
if (descriptor.schema && apiResponse.code >= 200 && apiResponse.code < 300) {
|
|
201
|
-
|
|
202
|
-
finalData = descriptor.schema.parse(transformed);
|
|
203
|
-
}
|
|
204
|
-
catch (error) {
|
|
205
|
-
// If validation fails, include the error in the response
|
|
206
|
-
console.error('Batch response validation failed:', error);
|
|
207
|
-
}
|
|
202
|
+
finalData = descriptor.schema.parse(transformed);
|
|
208
203
|
}
|
|
209
204
|
// Parse headers string into object
|
|
210
205
|
var headers = {};
|
|
@@ -261,7 +256,13 @@ var BatchBuilder = /** @class */ (function (_super) {
|
|
|
261
256
|
chunks = this.chunkRequests(__spreadArray([], requests, true), BatchBuilder.CHUNK_SIZE);
|
|
262
257
|
chunkPromises = chunks.map(function (chunk) {
|
|
263
258
|
return _this.executeSingleBatch(chunk).catch(function (error) {
|
|
264
|
-
//
|
|
259
|
+
// Rethrow schema validation errors — they indicate a programming
|
|
260
|
+
// issue (wrong schema or unexpected API response shape) and should
|
|
261
|
+
// not be silently swallowed.
|
|
262
|
+
if (error instanceof z.ZodError) {
|
|
263
|
+
throw error;
|
|
264
|
+
}
|
|
265
|
+
// Collect network/request errors but don't fail fast - allow other chunks to complete
|
|
265
266
|
console.error('Batch chunk failed:', error);
|
|
266
267
|
// Return error responses for all requests in this chunk
|
|
267
268
|
return chunk.map(function () { return ({
|
|
@@ -52,9 +52,10 @@ var CommentsClient = /** @class */ (function (_super) {
|
|
|
52
52
|
var method = 'GET';
|
|
53
53
|
var url = "".concat(ENDPOINT_COMMENTS, "/getone");
|
|
54
54
|
var params = { id: id };
|
|
55
|
-
|
|
55
|
+
// The API wraps the response in {"comment": {...}}, so we need to unwrap it
|
|
56
|
+
var wrappedSchema = z.object({ comment: CommentSchema }).transform(function (data) { return data.comment; });
|
|
56
57
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
57
|
-
return { method: method, url: url, params: params, schema:
|
|
58
|
+
return { method: method, url: url, params: params, schema: wrappedSchema };
|
|
58
59
|
}
|
|
59
60
|
return request({
|
|
60
61
|
httpMethod: method,
|
|
@@ -63,7 +64,7 @@ var CommentsClient = /** @class */ (function (_super) {
|
|
|
63
64
|
apiToken: this.apiToken,
|
|
64
65
|
payload: params,
|
|
65
66
|
customFetch: this.customFetch,
|
|
66
|
-
}).then(function (response) { return
|
|
67
|
+
}).then(function (response) { return wrappedSchema.parse(response.data); });
|
|
67
68
|
};
|
|
68
69
|
CommentsClient.prototype.createComment = function (args, options) {
|
|
69
70
|
var method = 'POST';
|
|
@@ -353,9 +353,10 @@ export var UnreadConversationSchema = z.object({
|
|
|
353
353
|
directMention: z.boolean(),
|
|
354
354
|
});
|
|
355
355
|
// SearchResult entity from API
|
|
356
|
+
export var SEARCH_RESULT_TYPES = ['thread', 'comment', 'message', 'conversation'];
|
|
356
357
|
export var SearchResultSchema = z.object({
|
|
357
358
|
id: z.string(),
|
|
358
|
-
type: z.enum(
|
|
359
|
+
type: z.enum(SEARCH_RESULT_TYPES),
|
|
359
360
|
snippet: z.string(),
|
|
360
361
|
snippetCreatorId: z.number(),
|
|
361
362
|
snippetLastUpdated: z.date(),
|
|
@@ -829,12 +829,15 @@ export declare const UnreadConversationSchema: z.ZodObject<{
|
|
|
829
829
|
directMention: z.ZodBoolean;
|
|
830
830
|
}, z.core.$strip>;
|
|
831
831
|
export type UnreadConversation = z.infer<typeof UnreadConversationSchema>;
|
|
832
|
+
export declare const SEARCH_RESULT_TYPES: readonly ["thread", "comment", "message", "conversation"];
|
|
833
|
+
export type SearchResultType = (typeof SEARCH_RESULT_TYPES)[number];
|
|
832
834
|
export declare const SearchResultSchema: z.ZodObject<{
|
|
833
835
|
id: z.ZodString;
|
|
834
836
|
type: z.ZodEnum<{
|
|
835
837
|
thread: "thread";
|
|
836
838
|
comment: "comment";
|
|
837
839
|
message: "message";
|
|
840
|
+
conversation: "conversation";
|
|
838
841
|
}>;
|
|
839
842
|
snippet: z.ZodString;
|
|
840
843
|
snippetCreatorId: z.ZodNumber;
|