hume 0.11.1 → 0.11.3
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/.mock/definition/empathic-voice/__package__.yml +24 -0
- package/.mock/definition/empathic-voice/configs.yml +2 -0
- package/.mock/definition/tts/__package__.yml +28 -0
- package/.mock/fern.config.json +1 -1
- package/Client.d.ts +11 -7
- package/Client.js +54 -6
- package/api/resources/empathicVoice/errors/BadRequestError.d.ts +2 -1
- package/api/resources/empathicVoice/errors/BadRequestError.js +2 -1
- package/api/resources/empathicVoice/resources/chatGroups/client/Client.d.ts +7 -3
- package/api/resources/empathicVoice/resources/chatGroups/client/Client.js +79 -52
- package/api/resources/empathicVoice/resources/chats/client/Client.d.ts +5 -2
- package/api/resources/empathicVoice/resources/chats/client/Client.js +59 -39
- package/api/resources/empathicVoice/resources/configs/client/Client.d.ts +17 -8
- package/api/resources/empathicVoice/resources/configs/client/Client.js +144 -83
- package/api/resources/empathicVoice/resources/configs/client/requests/PostedConfig.d.ts +1 -0
- package/api/resources/empathicVoice/resources/configs/client/requests/PostedConfigVersion.d.ts +1 -0
- package/api/resources/empathicVoice/resources/customVoices/client/Client.d.ts +13 -6
- package/api/resources/empathicVoice/resources/customVoices/client/Client.js +95 -53
- package/api/resources/empathicVoice/resources/prompts/client/Client.d.ts +19 -9
- package/api/resources/empathicVoice/resources/prompts/client/Client.js +143 -81
- package/api/resources/empathicVoice/resources/tools/client/Client.d.ts +17 -8
- package/api/resources/empathicVoice/resources/tools/client/Client.js +144 -83
- package/api/resources/empathicVoice/types/PostedNudgeSpec.d.ts +12 -0
- package/api/resources/empathicVoice/types/PostedNudgeSpec.js +5 -0
- package/api/resources/empathicVoice/types/ReturnConfig.d.ts +1 -0
- package/api/resources/empathicVoice/types/ReturnNudgeSpec.d.ts +12 -0
- package/api/resources/empathicVoice/types/ReturnNudgeSpec.js +5 -0
- package/api/resources/empathicVoice/types/WebhookEventChatStatus.d.ts +2 -1
- package/api/resources/empathicVoice/types/WebhookEventChatStatus.js +1 -0
- package/api/resources/empathicVoice/types/index.d.ts +2 -0
- package/api/resources/empathicVoice/types/index.js +2 -0
- package/api/resources/expressionMeasurement/client/Client.d.ts +2 -0
- package/api/resources/expressionMeasurement/resources/batch/client/Client.d.ts +15 -7
- package/api/resources/expressionMeasurement/resources/batch/client/Client.js +96 -52
- package/api/resources/tts/client/Client.d.ts +27 -19
- package/api/resources/tts/client/Client.js +89 -50
- package/api/resources/tts/client/index.d.ts +1 -1
- package/api/resources/tts/client/index.js +15 -0
- package/api/resources/tts/client/requests/SynthesizeJsonRequest.d.ts +36 -0
- package/api/resources/tts/client/requests/SynthesizeJsonRequest.js +5 -0
- package/api/resources/tts/client/requests/index.d.ts +1 -0
- package/api/resources/tts/client/requests/index.js +2 -0
- package/api/resources/tts/errors/BadRequestError.d.ts +2 -1
- package/api/resources/tts/errors/BadRequestError.js +2 -1
- package/api/resources/tts/errors/UnprocessableEntityError.d.ts +2 -1
- package/api/resources/tts/errors/UnprocessableEntityError.js +2 -1
- package/api/resources/tts/resources/voices/client/Client.d.ts +7 -3
- package/api/resources/tts/resources/voices/client/Client.js +49 -29
- package/api/resources/tts/types/Snippet.d.ts +2 -0
- package/api/resources/tts/types/SnippetAudioChunk.d.ts +2 -0
- package/core/fetcher/APIResponse.d.ts +10 -0
- package/core/fetcher/Fetcher.d.ts +2 -1
- package/core/fetcher/Fetcher.js +29 -9
- package/core/fetcher/Headers.d.ts +2 -0
- package/core/fetcher/Headers.js +84 -0
- package/core/fetcher/HttpResponsePromise.d.ts +58 -0
- package/core/fetcher/HttpResponsePromise.js +103 -0
- package/core/fetcher/RawResponse.d.ts +29 -0
- package/core/fetcher/RawResponse.js +44 -0
- package/core/fetcher/index.d.ts +3 -0
- package/core/fetcher/index.js +7 -1
- package/core/form-data-utils/FormDataWrapper.d.ts +3 -0
- package/core/form-data-utils/FormDataWrapper.js +53 -13
- package/core/form-data-utils/toReadableStream.d.ts +1 -0
- package/core/form-data-utils/toReadableStream.js +50 -0
- package/core/headers.d.ts +3 -0
- package/core/headers.js +29 -0
- package/core/index.d.ts +4 -4
- package/core/index.js +5 -4
- package/core/pagination/Page.d.ts +5 -2
- package/core/pagination/Page.js +5 -2
- package/core/pagination/Pageable.d.ts +2 -0
- package/core/runtime/runtime.js +0 -1
- package/dist/Client.d.ts +11 -7
- package/dist/Client.js +54 -6
- package/dist/api/resources/empathicVoice/errors/BadRequestError.d.ts +2 -1
- package/dist/api/resources/empathicVoice/errors/BadRequestError.js +2 -1
- package/dist/api/resources/empathicVoice/resources/chatGroups/client/Client.d.ts +7 -3
- package/dist/api/resources/empathicVoice/resources/chatGroups/client/Client.js +79 -52
- package/dist/api/resources/empathicVoice/resources/chats/client/Client.d.ts +5 -2
- package/dist/api/resources/empathicVoice/resources/chats/client/Client.js +59 -39
- package/dist/api/resources/empathicVoice/resources/configs/client/Client.d.ts +17 -8
- package/dist/api/resources/empathicVoice/resources/configs/client/Client.js +144 -83
- package/dist/api/resources/empathicVoice/resources/configs/client/requests/PostedConfig.d.ts +1 -0
- package/dist/api/resources/empathicVoice/resources/configs/client/requests/PostedConfigVersion.d.ts +1 -0
- package/dist/api/resources/empathicVoice/resources/customVoices/client/Client.d.ts +13 -6
- package/dist/api/resources/empathicVoice/resources/customVoices/client/Client.js +95 -53
- package/dist/api/resources/empathicVoice/resources/prompts/client/Client.d.ts +19 -9
- package/dist/api/resources/empathicVoice/resources/prompts/client/Client.js +143 -81
- package/dist/api/resources/empathicVoice/resources/tools/client/Client.d.ts +17 -8
- package/dist/api/resources/empathicVoice/resources/tools/client/Client.js +144 -83
- package/dist/api/resources/empathicVoice/types/PostedNudgeSpec.d.ts +12 -0
- package/dist/api/resources/empathicVoice/types/PostedNudgeSpec.js +5 -0
- package/dist/api/resources/empathicVoice/types/ReturnConfig.d.ts +1 -0
- package/dist/api/resources/empathicVoice/types/ReturnNudgeSpec.d.ts +12 -0
- package/dist/api/resources/empathicVoice/types/ReturnNudgeSpec.js +5 -0
- package/dist/api/resources/empathicVoice/types/WebhookEventChatStatus.d.ts +2 -1
- package/dist/api/resources/empathicVoice/types/WebhookEventChatStatus.js +1 -0
- package/dist/api/resources/empathicVoice/types/index.d.ts +2 -0
- package/dist/api/resources/empathicVoice/types/index.js +2 -0
- package/dist/api/resources/expressionMeasurement/client/Client.d.ts +2 -0
- package/dist/api/resources/expressionMeasurement/resources/batch/client/Client.d.ts +15 -7
- package/dist/api/resources/expressionMeasurement/resources/batch/client/Client.js +96 -52
- package/dist/api/resources/tts/client/Client.d.ts +27 -19
- package/dist/api/resources/tts/client/Client.js +89 -50
- package/dist/api/resources/tts/client/index.d.ts +1 -1
- package/dist/api/resources/tts/client/index.js +15 -0
- package/dist/api/resources/tts/client/requests/SynthesizeJsonRequest.d.ts +36 -0
- package/dist/api/resources/tts/client/requests/SynthesizeJsonRequest.js +5 -0
- package/dist/api/resources/tts/client/requests/index.d.ts +1 -0
- package/dist/api/resources/tts/client/requests/index.js +2 -0
- package/dist/api/resources/tts/errors/BadRequestError.d.ts +2 -1
- package/dist/api/resources/tts/errors/BadRequestError.js +2 -1
- package/dist/api/resources/tts/errors/UnprocessableEntityError.d.ts +2 -1
- package/dist/api/resources/tts/errors/UnprocessableEntityError.js +2 -1
- package/dist/api/resources/tts/resources/voices/client/Client.d.ts +7 -3
- package/dist/api/resources/tts/resources/voices/client/Client.js +49 -29
- package/dist/api/resources/tts/types/Snippet.d.ts +2 -0
- package/dist/api/resources/tts/types/SnippetAudioChunk.d.ts +2 -0
- package/dist/core/fetcher/APIResponse.d.ts +10 -0
- package/dist/core/fetcher/Fetcher.d.ts +2 -1
- package/dist/core/fetcher/Fetcher.js +29 -9
- package/dist/core/fetcher/Headers.d.ts +2 -0
- package/dist/core/fetcher/Headers.js +84 -0
- package/dist/core/fetcher/HttpResponsePromise.d.ts +58 -0
- package/dist/core/fetcher/HttpResponsePromise.js +103 -0
- package/dist/core/fetcher/RawResponse.d.ts +29 -0
- package/dist/core/fetcher/RawResponse.js +44 -0
- package/dist/core/fetcher/index.d.ts +3 -0
- package/dist/core/fetcher/index.js +7 -1
- package/dist/core/form-data-utils/FormDataWrapper.d.ts +3 -0
- package/dist/core/form-data-utils/FormDataWrapper.js +53 -13
- package/dist/core/form-data-utils/toReadableStream.d.ts +1 -0
- package/dist/core/form-data-utils/toReadableStream.js +50 -0
- package/dist/core/headers.d.ts +3 -0
- package/dist/core/headers.js +29 -0
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +5 -4
- package/dist/core/pagination/Page.d.ts +5 -2
- package/dist/core/pagination/Page.js +5 -2
- package/dist/core/pagination/Pageable.d.ts +2 -0
- package/dist/core/runtime/runtime.js +0 -1
- package/dist/errors/HumeError.d.ts +7 -2
- package/dist/errors/HumeError.js +10 -10
- package/dist/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfig.d.ts +2 -0
- package/dist/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfig.js +2 -0
- package/dist/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfigVersion.d.ts +2 -0
- package/dist/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfigVersion.js +2 -0
- package/dist/serialization/resources/empathicVoice/types/PostedNudgeSpec.d.ts +13 -0
- package/dist/serialization/resources/empathicVoice/types/PostedNudgeSpec.js +44 -0
- package/dist/serialization/resources/empathicVoice/types/ReturnConfig.d.ts +2 -0
- package/dist/serialization/resources/empathicVoice/types/ReturnConfig.js +2 -0
- package/dist/serialization/resources/empathicVoice/types/ReturnNudgeSpec.d.ts +13 -0
- package/dist/serialization/resources/empathicVoice/types/ReturnNudgeSpec.js +44 -0
- package/dist/serialization/resources/empathicVoice/types/WebhookEventChatStatus.d.ts +1 -1
- package/dist/serialization/resources/empathicVoice/types/WebhookEventChatStatus.js +1 -0
- package/dist/serialization/resources/empathicVoice/types/index.d.ts +2 -0
- package/dist/serialization/resources/empathicVoice/types/index.js +2 -0
- package/dist/serialization/resources/tts/types/Snippet.d.ts +1 -0
- package/dist/serialization/resources/tts/types/Snippet.js +1 -0
- package/dist/serialization/resources/tts/types/SnippetAudioChunk.d.ts +1 -0
- package/dist/serialization/resources/tts/types/SnippetAudioChunk.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/wrapper/expressionMeasurement/ExpressionMeasurementClient.js +2 -0
- package/dist/wrapper/expressionMeasurement/batch/BatchClient.d.ts +2 -1
- package/dist/wrapper/expressionMeasurement/batch/BatchClient.js +43 -17
- package/errors/HumeError.d.ts +7 -2
- package/errors/HumeError.js +10 -10
- package/package.json +9 -4
- package/reference.md +17 -15
- package/scripts/rename-to-esm-files.js +10 -2
- package/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfig.d.ts +2 -0
- package/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfig.js +2 -0
- package/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfigVersion.d.ts +2 -0
- package/serialization/resources/empathicVoice/resources/configs/client/requests/PostedConfigVersion.js +2 -0
- package/serialization/resources/empathicVoice/types/PostedNudgeSpec.d.ts +13 -0
- package/serialization/resources/empathicVoice/types/PostedNudgeSpec.js +44 -0
- package/serialization/resources/empathicVoice/types/ReturnConfig.d.ts +2 -0
- package/serialization/resources/empathicVoice/types/ReturnConfig.js +2 -0
- package/serialization/resources/empathicVoice/types/ReturnNudgeSpec.d.ts +13 -0
- package/serialization/resources/empathicVoice/types/ReturnNudgeSpec.js +44 -0
- package/serialization/resources/empathicVoice/types/WebhookEventChatStatus.d.ts +1 -1
- package/serialization/resources/empathicVoice/types/WebhookEventChatStatus.js +1 -0
- package/serialization/resources/empathicVoice/types/index.d.ts +2 -0
- package/serialization/resources/empathicVoice/types/index.js +2 -0
- package/serialization/resources/tts/types/Snippet.d.ts +1 -0
- package/serialization/resources/tts/types/Snippet.js +1 -0
- package/serialization/resources/tts/types/SnippetAudioChunk.d.ts +1 -0
- package/serialization/resources/tts/types/SnippetAudioChunk.js +1 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/wrapper/expressionMeasurement/ExpressionMeasurementClient.js +2 -0
- package/wrapper/expressionMeasurement/batch/BatchClient.d.ts +2 -1
- package/wrapper/expressionMeasurement/batch/BatchClient.js +43 -17
- /package/core/{streaming-fetcher → stream}/Stream.d.ts +0 -0
- /package/core/{streaming-fetcher → stream}/Stream.js +0 -0
- /package/core/{streaming-fetcher → stream}/index.d.ts +0 -0
- /package/core/{streaming-fetcher → stream}/index.js +0 -0
- /package/dist/core/{streaming-fetcher → stream}/Stream.d.ts +0 -0
- /package/dist/core/{streaming-fetcher → stream}/Stream.js +0 -0
- /package/dist/core/{streaming-fetcher → stream}/index.d.ts +0 -0
- /package/dist/core/{streaming-fetcher → stream}/index.js +0 -0
|
@@ -53,6 +53,7 @@ const environments = __importStar(require("../../../../../../environments"));
|
|
|
53
53
|
const core = __importStar(require("../../../../../../core"));
|
|
54
54
|
const Hume = __importStar(require("../../../../../index"));
|
|
55
55
|
const serializers = __importStar(require("../../../../../../serialization/index"));
|
|
56
|
+
const headers_js_1 = require("../../../../../../core/headers.js");
|
|
56
57
|
const url_join_1 = __importDefault(require("url-join"));
|
|
57
58
|
const errors = __importStar(require("../../../../../../errors/index"));
|
|
58
59
|
class Voices {
|
|
@@ -74,8 +75,8 @@ class Voices {
|
|
|
74
75
|
*/
|
|
75
76
|
list(request, requestOptions) {
|
|
76
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
const list = (request) => __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
var _a, _b, _c;
|
|
78
|
+
const list = core.HttpResponsePromise.interceptFunction((request) => __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
var _a, _b, _c, _d;
|
|
79
80
|
const { provider, pageNumber, pageSize, ascendingOrder } = request;
|
|
80
81
|
const _queryParams = {};
|
|
81
82
|
_queryParams["provider"] = serializers.tts.VoiceProvider.jsonOrThrow(provider, {
|
|
@@ -93,21 +94,22 @@ class Voices {
|
|
|
93
94
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
94
95
|
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.HumeEnvironment.Production, "v0/tts/voices"),
|
|
95
96
|
method: "GET",
|
|
96
|
-
headers:
|
|
97
|
-
contentType: "application/json",
|
|
97
|
+
headers: (0, headers_js_1.mergeHeaders)((_d = this._options) === null || _d === void 0 ? void 0 : _d.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)(Object.assign({}, (yield this._getCustomAuthorizationHeaders()))), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
|
|
98
98
|
queryParameters: _queryParams,
|
|
99
|
-
requestType: "json",
|
|
100
99
|
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
|
|
101
100
|
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
|
|
102
101
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
103
102
|
});
|
|
104
103
|
if (_response.ok) {
|
|
105
|
-
return
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
return {
|
|
105
|
+
data: serializers.tts.ReturnPagedVoices.parseOrThrow(_response.body, {
|
|
106
|
+
unrecognizedObjectKeys: "passthrough",
|
|
107
|
+
allowUnrecognizedUnionMembers: true,
|
|
108
|
+
allowUnrecognizedEnumValues: true,
|
|
109
|
+
breadcrumbsPrefix: ["response"],
|
|
110
|
+
}),
|
|
111
|
+
rawResponse: _response.rawResponse,
|
|
112
|
+
};
|
|
111
113
|
}
|
|
112
114
|
if (_response.error.reason === "status-code") {
|
|
113
115
|
switch (_response.error.statusCode) {
|
|
@@ -117,11 +119,12 @@ class Voices {
|
|
|
117
119
|
allowUnrecognizedUnionMembers: true,
|
|
118
120
|
allowUnrecognizedEnumValues: true,
|
|
119
121
|
breadcrumbsPrefix: ["response"],
|
|
120
|
-
}));
|
|
122
|
+
}), _response.rawResponse);
|
|
121
123
|
default:
|
|
122
124
|
throw new errors.HumeError({
|
|
123
125
|
statusCode: _response.error.statusCode,
|
|
124
126
|
body: _response.error.body,
|
|
127
|
+
rawResponse: _response.rawResponse,
|
|
125
128
|
});
|
|
126
129
|
}
|
|
127
130
|
}
|
|
@@ -130,18 +133,22 @@ class Voices {
|
|
|
130
133
|
throw new errors.HumeError({
|
|
131
134
|
statusCode: _response.error.statusCode,
|
|
132
135
|
body: _response.error.rawBody,
|
|
136
|
+
rawResponse: _response.rawResponse,
|
|
133
137
|
});
|
|
134
138
|
case "timeout":
|
|
135
139
|
throw new errors.HumeTimeoutError("Timeout exceeded when calling GET /v0/tts/voices.");
|
|
136
140
|
case "unknown":
|
|
137
141
|
throw new errors.HumeError({
|
|
138
142
|
message: _response.error.errorMessage,
|
|
143
|
+
rawResponse: _response.rawResponse,
|
|
139
144
|
});
|
|
140
145
|
}
|
|
141
|
-
});
|
|
146
|
+
}));
|
|
142
147
|
let _offset = (request === null || request === void 0 ? void 0 : request.pageNumber) != null ? request === null || request === void 0 ? void 0 : request.pageNumber : 0;
|
|
148
|
+
const dataWithRawResponse = yield list(request).withRawResponse();
|
|
143
149
|
return new core.Pageable({
|
|
144
|
-
response:
|
|
150
|
+
response: dataWithRawResponse.data,
|
|
151
|
+
rawResponse: dataWithRawResponse.rawResponse,
|
|
145
152
|
hasNextPage: (response) => { var _a; return ((_a = response === null || response === void 0 ? void 0 : response.voicesPage) !== null && _a !== void 0 ? _a : []).length > 0; },
|
|
146
153
|
getItems: (response) => { var _a; return (_a = response === null || response === void 0 ? void 0 : response.voicesPage) !== null && _a !== void 0 ? _a : []; },
|
|
147
154
|
loadPage: (_response) => {
|
|
@@ -168,12 +175,15 @@ class Voices {
|
|
|
168
175
|
* })
|
|
169
176
|
*/
|
|
170
177
|
create(request, requestOptions) {
|
|
178
|
+
return core.HttpResponsePromise.fromPromise(this.__create(request, requestOptions));
|
|
179
|
+
}
|
|
180
|
+
__create(request, requestOptions) {
|
|
171
181
|
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
-
var _a, _b, _c;
|
|
182
|
+
var _a, _b, _c, _d;
|
|
173
183
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
174
184
|
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.HumeEnvironment.Production, "v0/tts/voices"),
|
|
175
185
|
method: "POST",
|
|
176
|
-
headers:
|
|
186
|
+
headers: (0, headers_js_1.mergeHeaders)((_d = this._options) === null || _d === void 0 ? void 0 : _d.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)(Object.assign({}, (yield this._getCustomAuthorizationHeaders()))), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
|
|
177
187
|
contentType: "application/json",
|
|
178
188
|
requestType: "json",
|
|
179
189
|
body: serializers.tts.PostedVoice.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
|
|
@@ -182,12 +192,15 @@ class Voices {
|
|
|
182
192
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
183
193
|
});
|
|
184
194
|
if (_response.ok) {
|
|
185
|
-
return
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
195
|
+
return {
|
|
196
|
+
data: serializers.tts.ReturnVoice.parseOrThrow(_response.body, {
|
|
197
|
+
unrecognizedObjectKeys: "passthrough",
|
|
198
|
+
allowUnrecognizedUnionMembers: true,
|
|
199
|
+
allowUnrecognizedEnumValues: true,
|
|
200
|
+
breadcrumbsPrefix: ["response"],
|
|
201
|
+
}),
|
|
202
|
+
rawResponse: _response.rawResponse,
|
|
203
|
+
};
|
|
191
204
|
}
|
|
192
205
|
if (_response.error.reason === "status-code") {
|
|
193
206
|
switch (_response.error.statusCode) {
|
|
@@ -197,11 +210,12 @@ class Voices {
|
|
|
197
210
|
allowUnrecognizedUnionMembers: true,
|
|
198
211
|
allowUnrecognizedEnumValues: true,
|
|
199
212
|
breadcrumbsPrefix: ["response"],
|
|
200
|
-
}));
|
|
213
|
+
}), _response.rawResponse);
|
|
201
214
|
default:
|
|
202
215
|
throw new errors.HumeError({
|
|
203
216
|
statusCode: _response.error.statusCode,
|
|
204
217
|
body: _response.error.body,
|
|
218
|
+
rawResponse: _response.rawResponse,
|
|
205
219
|
});
|
|
206
220
|
}
|
|
207
221
|
}
|
|
@@ -210,12 +224,14 @@ class Voices {
|
|
|
210
224
|
throw new errors.HumeError({
|
|
211
225
|
statusCode: _response.error.statusCode,
|
|
212
226
|
body: _response.error.rawBody,
|
|
227
|
+
rawResponse: _response.rawResponse,
|
|
213
228
|
});
|
|
214
229
|
case "timeout":
|
|
215
230
|
throw new errors.HumeTimeoutError("Timeout exceeded when calling POST /v0/tts/voices.");
|
|
216
231
|
case "unknown":
|
|
217
232
|
throw new errors.HumeError({
|
|
218
233
|
message: _response.error.errorMessage,
|
|
234
|
+
rawResponse: _response.rawResponse,
|
|
219
235
|
});
|
|
220
236
|
}
|
|
221
237
|
});
|
|
@@ -234,24 +250,25 @@ class Voices {
|
|
|
234
250
|
* })
|
|
235
251
|
*/
|
|
236
252
|
delete(request, requestOptions) {
|
|
253
|
+
return core.HttpResponsePromise.fromPromise(this.__delete(request, requestOptions));
|
|
254
|
+
}
|
|
255
|
+
__delete(request, requestOptions) {
|
|
237
256
|
return __awaiter(this, void 0, void 0, function* () {
|
|
238
|
-
var _a, _b, _c;
|
|
257
|
+
var _a, _b, _c, _d;
|
|
239
258
|
const { name } = request;
|
|
240
259
|
const _queryParams = {};
|
|
241
260
|
_queryParams["name"] = name;
|
|
242
261
|
const _response = yield ((_a = this._options.fetcher) !== null && _a !== void 0 ? _a : core.fetcher)({
|
|
243
262
|
url: (0, url_join_1.default)((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.HumeEnvironment.Production, "v0/tts/voices"),
|
|
244
263
|
method: "DELETE",
|
|
245
|
-
headers:
|
|
246
|
-
contentType: "application/json",
|
|
264
|
+
headers: (0, headers_js_1.mergeHeaders)((_d = this._options) === null || _d === void 0 ? void 0 : _d.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)(Object.assign({}, (yield this._getCustomAuthorizationHeaders()))), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
|
|
247
265
|
queryParameters: _queryParams,
|
|
248
|
-
requestType: "json",
|
|
249
266
|
timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
|
|
250
267
|
maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
|
|
251
268
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
252
269
|
});
|
|
253
270
|
if (_response.ok) {
|
|
254
|
-
return;
|
|
271
|
+
return { data: undefined, rawResponse: _response.rawResponse };
|
|
255
272
|
}
|
|
256
273
|
if (_response.error.reason === "status-code") {
|
|
257
274
|
switch (_response.error.statusCode) {
|
|
@@ -261,11 +278,12 @@ class Voices {
|
|
|
261
278
|
allowUnrecognizedUnionMembers: true,
|
|
262
279
|
allowUnrecognizedEnumValues: true,
|
|
263
280
|
breadcrumbsPrefix: ["response"],
|
|
264
|
-
}));
|
|
281
|
+
}), _response.rawResponse);
|
|
265
282
|
default:
|
|
266
283
|
throw new errors.HumeError({
|
|
267
284
|
statusCode: _response.error.statusCode,
|
|
268
285
|
body: _response.error.body,
|
|
286
|
+
rawResponse: _response.rawResponse,
|
|
269
287
|
});
|
|
270
288
|
}
|
|
271
289
|
}
|
|
@@ -274,12 +292,14 @@ class Voices {
|
|
|
274
292
|
throw new errors.HumeError({
|
|
275
293
|
statusCode: _response.error.statusCode,
|
|
276
294
|
body: _response.error.rawBody,
|
|
295
|
+
rawResponse: _response.rawResponse,
|
|
277
296
|
});
|
|
278
297
|
case "timeout":
|
|
279
298
|
throw new errors.HumeTimeoutError("Timeout exceeded when calling DELETE /v0/tts/voices.");
|
|
280
299
|
case "unknown":
|
|
281
300
|
throw new errors.HumeError({
|
|
282
301
|
message: _response.error.errorMessage,
|
|
302
|
+
rawResponse: _response.rawResponse,
|
|
283
303
|
});
|
|
284
304
|
}
|
|
285
305
|
});
|
|
@@ -10,6 +10,8 @@ export interface Snippet {
|
|
|
10
10
|
id: string;
|
|
11
11
|
/** The text for this **Snippet**. */
|
|
12
12
|
text: string;
|
|
13
|
+
/** The transcribed text of the generated audio. It is only present if `instant_mode` is set to `false`. */
|
|
14
|
+
transcribedText?: string;
|
|
13
15
|
/** The index of the utterance in the request this snippet corresponds to. */
|
|
14
16
|
utteranceIndex?: number;
|
|
15
17
|
}
|
|
@@ -14,6 +14,8 @@ export interface SnippetAudioChunk {
|
|
|
14
14
|
snippetId: string;
|
|
15
15
|
/** The text of the parent snippet that this chunk corresponds to. */
|
|
16
16
|
text: string;
|
|
17
|
+
/** The transcribed text of the generated audio of the parent snippet that this chunk corresponds to. It is only present if `instant_mode` is set to `false`. */
|
|
18
|
+
transcribedText?: string;
|
|
17
19
|
/** The index of the utterance in the request that the parent snippet of this chunk corresponds to. */
|
|
18
20
|
utteranceIndex?: number;
|
|
19
21
|
}
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
+
import { RawResponse } from "./RawResponse";
|
|
2
|
+
/**
|
|
3
|
+
* The response of an API call.
|
|
4
|
+
* It is a successful response or a failed response.
|
|
5
|
+
*/
|
|
1
6
|
export type APIResponse<Success, Failure> = SuccessfulResponse<Success> | FailedResponse<Failure>;
|
|
2
7
|
export interface SuccessfulResponse<T> {
|
|
3
8
|
ok: true;
|
|
4
9
|
body: T;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `rawResponse` instead
|
|
12
|
+
*/
|
|
5
13
|
headers?: Record<string, any>;
|
|
14
|
+
rawResponse: RawResponse;
|
|
6
15
|
}
|
|
7
16
|
export interface FailedResponse<T> {
|
|
8
17
|
ok: false;
|
|
9
18
|
error: T;
|
|
19
|
+
rawResponse: RawResponse;
|
|
10
20
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { APIResponse } from "./APIResponse";
|
|
2
|
+
import { Supplier } from "./Supplier";
|
|
2
3
|
export type FetchFunction = <R = unknown>(args: Fetcher.Args) => Promise<APIResponse<R, Fetcher.Error>>;
|
|
3
4
|
export declare namespace Fetcher {
|
|
4
5
|
interface Args {
|
|
5
6
|
url: string;
|
|
6
7
|
method: string;
|
|
7
8
|
contentType?: string;
|
|
8
|
-
headers?: Record<string, string | undefined>;
|
|
9
|
+
headers?: Record<string, string | Supplier<string | undefined> | undefined>;
|
|
9
10
|
queryParameters?: Record<string, string | string[] | object | object[] | null>;
|
|
10
11
|
body?: unknown;
|
|
11
12
|
timeoutMs?: number;
|
package/core/fetcher/Fetcher.js
CHANGED
|
@@ -12,25 +12,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.fetcher = void 0;
|
|
13
13
|
exports.fetcherImpl = fetcherImpl;
|
|
14
14
|
const json_1 = require("../json");
|
|
15
|
+
const RawResponse_1 = require("./RawResponse");
|
|
16
|
+
const Supplier_1 = require("./Supplier");
|
|
15
17
|
const createRequestUrl_1 = require("./createRequestUrl");
|
|
16
18
|
const getFetchFn_1 = require("./getFetchFn");
|
|
17
19
|
const getRequestBody_1 = require("./getRequestBody");
|
|
18
20
|
const getResponseBody_1 = require("./getResponseBody");
|
|
19
21
|
const makeRequest_1 = require("./makeRequest");
|
|
20
22
|
const requestWithRetries_1 = require("./requestWithRetries");
|
|
21
|
-
function
|
|
23
|
+
function getHeaders(args) {
|
|
22
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const
|
|
25
|
+
const newHeaders = {};
|
|
24
26
|
if (args.body !== undefined && args.contentType != null) {
|
|
25
|
-
|
|
27
|
+
newHeaders["Content-Type"] = args.contentType;
|
|
28
|
+
}
|
|
29
|
+
if (args.headers == null) {
|
|
30
|
+
return newHeaders;
|
|
26
31
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
for (const [key, value] of Object.entries(args.headers)) {
|
|
33
|
+
const result = yield Supplier_1.Supplier.get(value);
|
|
34
|
+
if (typeof result === "string") {
|
|
35
|
+
newHeaders[key] = result;
|
|
36
|
+
continue;
|
|
32
37
|
}
|
|
38
|
+
if (result == null) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
newHeaders[key] = `${result}`;
|
|
33
42
|
}
|
|
43
|
+
return newHeaders;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function fetcherImpl(args) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
48
|
const url = (0, createRequestUrl_1.createRequestUrl)(args.url, args.queryParameters);
|
|
35
49
|
const requestBody = yield (0, getRequestBody_1.getRequestBody)({
|
|
36
50
|
body: args.body,
|
|
@@ -39,7 +53,7 @@ function fetcherImpl(args) {
|
|
|
39
53
|
const fetchFn = yield (0, getFetchFn_1.getFetchFn)();
|
|
40
54
|
try {
|
|
41
55
|
const response = yield (0, requestWithRetries_1.requestWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
return (0, makeRequest_1.makeRequest)(fetchFn, url, args.method,
|
|
56
|
+
return (0, makeRequest_1.makeRequest)(fetchFn, url, args.method, yield getHeaders(args), requestBody, args.timeoutMs, args.abortSignal, args.withCredentials, args.duplex);
|
|
43
57
|
}), args.maxRetries);
|
|
44
58
|
const responseBody = yield (0, getResponseBody_1.getResponseBody)(response, args.responseType);
|
|
45
59
|
if (response.status >= 200 && response.status < 400) {
|
|
@@ -47,6 +61,7 @@ function fetcherImpl(args) {
|
|
|
47
61
|
ok: true,
|
|
48
62
|
body: responseBody,
|
|
49
63
|
headers: response.headers,
|
|
64
|
+
rawResponse: (0, RawResponse_1.toRawResponse)(response),
|
|
50
65
|
};
|
|
51
66
|
}
|
|
52
67
|
else {
|
|
@@ -57,6 +72,7 @@ function fetcherImpl(args) {
|
|
|
57
72
|
statusCode: response.status,
|
|
58
73
|
body: responseBody,
|
|
59
74
|
},
|
|
75
|
+
rawResponse: (0, RawResponse_1.toRawResponse)(response),
|
|
60
76
|
};
|
|
61
77
|
}
|
|
62
78
|
}
|
|
@@ -68,6 +84,7 @@ function fetcherImpl(args) {
|
|
|
68
84
|
reason: "unknown",
|
|
69
85
|
errorMessage: "The user aborted a request",
|
|
70
86
|
},
|
|
87
|
+
rawResponse: RawResponse_1.abortRawResponse,
|
|
71
88
|
};
|
|
72
89
|
}
|
|
73
90
|
else if (error instanceof Error && error.name === "AbortError") {
|
|
@@ -76,6 +93,7 @@ function fetcherImpl(args) {
|
|
|
76
93
|
error: {
|
|
77
94
|
reason: "timeout",
|
|
78
95
|
},
|
|
96
|
+
rawResponse: RawResponse_1.abortRawResponse,
|
|
79
97
|
};
|
|
80
98
|
}
|
|
81
99
|
else if (error instanceof Error) {
|
|
@@ -85,6 +103,7 @@ function fetcherImpl(args) {
|
|
|
85
103
|
reason: "unknown",
|
|
86
104
|
errorMessage: error.message,
|
|
87
105
|
},
|
|
106
|
+
rawResponse: RawResponse_1.unknownRawResponse,
|
|
88
107
|
};
|
|
89
108
|
}
|
|
90
109
|
return {
|
|
@@ -93,6 +112,7 @@ function fetcherImpl(args) {
|
|
|
93
112
|
reason: "unknown",
|
|
94
113
|
errorMessage: (0, json_1.toJson)(error),
|
|
95
114
|
},
|
|
115
|
+
rawResponse: RawResponse_1.unknownRawResponse,
|
|
96
116
|
};
|
|
97
117
|
}
|
|
98
118
|
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Headers = void 0;
|
|
4
|
+
let Headers;
|
|
5
|
+
if (typeof globalThis.Headers !== "undefined") {
|
|
6
|
+
exports.Headers = Headers = globalThis.Headers;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
exports.Headers = Headers = class Headers {
|
|
10
|
+
constructor(init) {
|
|
11
|
+
this.headers = new Map();
|
|
12
|
+
if (init) {
|
|
13
|
+
if (init instanceof Headers) {
|
|
14
|
+
init.forEach((value, key) => this.append(key, value));
|
|
15
|
+
}
|
|
16
|
+
else if (Array.isArray(init)) {
|
|
17
|
+
for (const [key, value] of init) {
|
|
18
|
+
if (typeof key === "string" && typeof value === "string") {
|
|
19
|
+
this.append(key, value);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
throw new TypeError("Each header entry must be a [string, string] tuple");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
for (const [key, value] of Object.entries(init)) {
|
|
28
|
+
if (typeof value === "string") {
|
|
29
|
+
this.append(key, value);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new TypeError("Header values must be strings");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
append(name, value) {
|
|
39
|
+
const key = name.toLowerCase();
|
|
40
|
+
const existing = this.headers.get(key) || [];
|
|
41
|
+
this.headers.set(key, [...existing, value]);
|
|
42
|
+
}
|
|
43
|
+
delete(name) {
|
|
44
|
+
const key = name.toLowerCase();
|
|
45
|
+
this.headers.delete(key);
|
|
46
|
+
}
|
|
47
|
+
get(name) {
|
|
48
|
+
const key = name.toLowerCase();
|
|
49
|
+
const values = this.headers.get(key);
|
|
50
|
+
return values ? values.join(", ") : null;
|
|
51
|
+
}
|
|
52
|
+
has(name) {
|
|
53
|
+
const key = name.toLowerCase();
|
|
54
|
+
return this.headers.has(key);
|
|
55
|
+
}
|
|
56
|
+
set(name, value) {
|
|
57
|
+
const key = name.toLowerCase();
|
|
58
|
+
this.headers.set(key, [value]);
|
|
59
|
+
}
|
|
60
|
+
forEach(callbackfn, thisArg) {
|
|
61
|
+
const boundCallback = thisArg ? callbackfn.bind(thisArg) : callbackfn;
|
|
62
|
+
this.headers.forEach((values, key) => boundCallback(values.join(", "), key, this));
|
|
63
|
+
}
|
|
64
|
+
getSetCookie() {
|
|
65
|
+
return this.headers.get("set-cookie") || [];
|
|
66
|
+
}
|
|
67
|
+
*entries() {
|
|
68
|
+
for (const [key, values] of this.headers.entries()) {
|
|
69
|
+
yield [key, values.join(", ")];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
*keys() {
|
|
73
|
+
yield* this.headers.keys();
|
|
74
|
+
}
|
|
75
|
+
*values() {
|
|
76
|
+
for (const values of this.headers.values()) {
|
|
77
|
+
yield values.join(", ");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
[Symbol.iterator]() {
|
|
81
|
+
return this.entries();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { WithRawResponse } from "./RawResponse";
|
|
2
|
+
/**
|
|
3
|
+
* A promise that returns the parsed response and lets you retrieve the raw response too.
|
|
4
|
+
*/
|
|
5
|
+
export declare class HttpResponsePromise<T> extends Promise<T> {
|
|
6
|
+
private innerPromise;
|
|
7
|
+
private unwrappedPromise;
|
|
8
|
+
private constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Creates an `HttpResponsePromise` from a function that returns a promise.
|
|
11
|
+
*
|
|
12
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
13
|
+
* @param args - Arguments to pass to the function.
|
|
14
|
+
* @returns An `HttpResponsePromise` instance.
|
|
15
|
+
*/
|
|
16
|
+
static fromFunction<F extends (...args: never[]) => Promise<WithRawResponse<T>>, T>(fn: F, ...args: Parameters<F>): HttpResponsePromise<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a function that returns an `HttpResponsePromise` from a function that returns a promise.
|
|
19
|
+
*
|
|
20
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
21
|
+
* @returns A function that returns an `HttpResponsePromise` instance.
|
|
22
|
+
*/
|
|
23
|
+
static interceptFunction<F extends (...args: never[]) => Promise<WithRawResponse<T>>, T = Awaited<ReturnType<F>>["data"]>(fn: F): (...args: Parameters<F>) => HttpResponsePromise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates an `HttpResponsePromise` from an existing promise.
|
|
26
|
+
*
|
|
27
|
+
* @param promise - A promise resolving to a `WithRawResponse` object.
|
|
28
|
+
* @returns An `HttpResponsePromise` instance.
|
|
29
|
+
*/
|
|
30
|
+
static fromPromise<T>(promise: Promise<WithRawResponse<T>>): HttpResponsePromise<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates an `HttpResponsePromise` from an executor function.
|
|
33
|
+
*
|
|
34
|
+
* @param executor - A function that takes resolve and reject callbacks to create a promise.
|
|
35
|
+
* @returns An `HttpResponsePromise` instance.
|
|
36
|
+
*/
|
|
37
|
+
static fromExecutor<T>(executor: (resolve: (value: WithRawResponse<T>) => void, reject: (reason?: unknown) => void) => void): HttpResponsePromise<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Creates an `HttpResponsePromise` from a resolved result.
|
|
40
|
+
*
|
|
41
|
+
* @param result - A `WithRawResponse` object to resolve immediately.
|
|
42
|
+
* @returns An `HttpResponsePromise` instance.
|
|
43
|
+
*/
|
|
44
|
+
static fromResult<T>(result: WithRawResponse<T>): HttpResponsePromise<T>;
|
|
45
|
+
private unwrap;
|
|
46
|
+
/** @inheritdoc */
|
|
47
|
+
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
48
|
+
/** @inheritdoc */
|
|
49
|
+
catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
|
|
50
|
+
/** @inheritdoc */
|
|
51
|
+
finally(onfinally?: (() => void) | null): Promise<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves the data and raw response.
|
|
54
|
+
*
|
|
55
|
+
* @returns A promise resolving to a `WithRawResponse` object.
|
|
56
|
+
*/
|
|
57
|
+
withRawResponse(): Promise<WithRawResponse<T>>;
|
|
58
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HttpResponsePromise = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* A promise that returns the parsed response and lets you retrieve the raw response too.
|
|
15
|
+
*/
|
|
16
|
+
class HttpResponsePromise extends Promise {
|
|
17
|
+
constructor(promise) {
|
|
18
|
+
// Initialize with a no-op to avoid premature parsing
|
|
19
|
+
super((resolve) => {
|
|
20
|
+
resolve(undefined);
|
|
21
|
+
});
|
|
22
|
+
this.innerPromise = promise;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates an `HttpResponsePromise` from a function that returns a promise.
|
|
26
|
+
*
|
|
27
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
28
|
+
* @param args - Arguments to pass to the function.
|
|
29
|
+
* @returns An `HttpResponsePromise` instance.
|
|
30
|
+
*/
|
|
31
|
+
static fromFunction(fn, ...args) {
|
|
32
|
+
return new HttpResponsePromise(fn(...args));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates a function that returns an `HttpResponsePromise` from a function that returns a promise.
|
|
36
|
+
*
|
|
37
|
+
* @param fn - A function that returns a promise resolving to a `WithRawResponse` object.
|
|
38
|
+
* @returns A function that returns an `HttpResponsePromise` instance.
|
|
39
|
+
*/
|
|
40
|
+
static interceptFunction(fn) {
|
|
41
|
+
return (...args) => {
|
|
42
|
+
return HttpResponsePromise.fromPromise(fn(...args));
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates an `HttpResponsePromise` from an existing promise.
|
|
47
|
+
*
|
|
48
|
+
* @param promise - A promise resolving to a `WithRawResponse` object.
|
|
49
|
+
* @returns An `HttpResponsePromise` instance.
|
|
50
|
+
*/
|
|
51
|
+
static fromPromise(promise) {
|
|
52
|
+
return new HttpResponsePromise(promise);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates an `HttpResponsePromise` from an executor function.
|
|
56
|
+
*
|
|
57
|
+
* @param executor - A function that takes resolve and reject callbacks to create a promise.
|
|
58
|
+
* @returns An `HttpResponsePromise` instance.
|
|
59
|
+
*/
|
|
60
|
+
static fromExecutor(executor) {
|
|
61
|
+
const promise = new Promise(executor);
|
|
62
|
+
return new HttpResponsePromise(promise);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Creates an `HttpResponsePromise` from a resolved result.
|
|
66
|
+
*
|
|
67
|
+
* @param result - A `WithRawResponse` object to resolve immediately.
|
|
68
|
+
* @returns An `HttpResponsePromise` instance.
|
|
69
|
+
*/
|
|
70
|
+
static fromResult(result) {
|
|
71
|
+
const promise = Promise.resolve(result);
|
|
72
|
+
return new HttpResponsePromise(promise);
|
|
73
|
+
}
|
|
74
|
+
unwrap() {
|
|
75
|
+
if (!this.unwrappedPromise) {
|
|
76
|
+
this.unwrappedPromise = this.innerPromise.then(({ data }) => data);
|
|
77
|
+
}
|
|
78
|
+
return this.unwrappedPromise;
|
|
79
|
+
}
|
|
80
|
+
/** @inheritdoc */
|
|
81
|
+
then(onfulfilled, onrejected) {
|
|
82
|
+
return this.unwrap().then(onfulfilled, onrejected);
|
|
83
|
+
}
|
|
84
|
+
/** @inheritdoc */
|
|
85
|
+
catch(onrejected) {
|
|
86
|
+
return this.unwrap().catch(onrejected);
|
|
87
|
+
}
|
|
88
|
+
/** @inheritdoc */
|
|
89
|
+
finally(onfinally) {
|
|
90
|
+
return this.unwrap().finally(onfinally);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Retrieves the data and raw response.
|
|
94
|
+
*
|
|
95
|
+
* @returns A promise resolving to a `WithRawResponse` object.
|
|
96
|
+
*/
|
|
97
|
+
withRawResponse() {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
return yield this.innerPromise;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.HttpResponsePromise = HttpResponsePromise;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The raw response from the fetch call excluding the body.
|
|
3
|
+
*/
|
|
4
|
+
export type RawResponse = Omit<{
|
|
5
|
+
[K in keyof Response as Response[K] extends Function ? never : K]: Response[K];
|
|
6
|
+
}, "ok" | "body" | "bodyUsed">;
|
|
7
|
+
/**
|
|
8
|
+
* A raw response indicating that the request was aborted.
|
|
9
|
+
*/
|
|
10
|
+
export declare const abortRawResponse: RawResponse;
|
|
11
|
+
/**
|
|
12
|
+
* A raw response indicating an unknown error.
|
|
13
|
+
*/
|
|
14
|
+
export declare const unknownRawResponse: RawResponse;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a `RawResponse` object into a `RawResponse` by extracting its properties,
|
|
17
|
+
* excluding the `body` and `bodyUsed` fields.
|
|
18
|
+
*
|
|
19
|
+
* @param response - The `RawResponse` object to convert.
|
|
20
|
+
* @returns A `RawResponse` object containing the extracted properties of the input response.
|
|
21
|
+
*/
|
|
22
|
+
export declare function toRawResponse(response: Response): RawResponse;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a `RawResponse` from a standard `Response` object.
|
|
25
|
+
*/
|
|
26
|
+
export interface WithRawResponse<T> {
|
|
27
|
+
readonly data: T;
|
|
28
|
+
readonly rawResponse: RawResponse;
|
|
29
|
+
}
|