@doist/twist-sdk 2.1.0 → 2.1.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.
|
@@ -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';
|
|
@@ -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';
|