mavenagi 1.2.60 → 1.2.61
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/BaseClient.d.ts +12 -0
- package/BaseClient.js +5 -3
- package/Client.d.ts +3 -0
- package/Client.js +33 -28
- package/api/resources/actions/client/Client.d.ts +10 -0
- package/api/resources/actions/client/Client.js +14 -3
- package/api/resources/agents/client/Client.d.ts +12 -0
- package/api/resources/agents/client/Client.js +16 -3
- package/api/resources/agents/client/requests/AgentPatchRequest.d.ts +3 -3
- package/api/resources/agents/types/AgentPrompting.d.ts +3 -3
- package/api/resources/analytics/client/Client.d.ts +14 -0
- package/api/resources/analytics/client/Client.js +22 -7
- package/api/resources/analytics/types/ConversationMedian.d.ts +4 -0
- package/api/resources/analytics/types/ConversationPercentile.d.ts +4 -0
- package/api/resources/analytics/types/RowBase.d.ts +5 -1
- package/api/resources/analytics/types/Series.d.ts +4 -1
- package/api/resources/analytics/types/TimeSeries.d.ts +5 -1
- package/api/resources/appDirectory/client/Client.d.ts +12 -0
- package/api/resources/appDirectory/client/Client.js +16 -3
- package/api/resources/appSettings/client/Client.d.ts +6 -0
- package/api/resources/appSettings/client/Client.js +8 -1
- package/api/resources/assets/client/Client.d.ts +4 -0
- package/api/resources/assets/client/Client.js +7 -2
- package/api/resources/charters/client/Client.d.ts +245 -0
- package/api/resources/charters/client/Client.js +884 -0
- package/api/resources/charters/client/index.d.ts +1 -0
- package/api/resources/charters/client/index.js +17 -0
- package/api/resources/charters/client/requests/CharterDeleteRequest.d.ts +20 -0
- package/api/resources/charters/client/requests/CharterDeleteRequest.js +3 -0
- package/api/resources/charters/client/requests/CharterGetAncestorsRequest.d.ts +8 -0
- package/api/resources/charters/client/requests/CharterGetAncestorsRequest.js +3 -0
- package/api/resources/charters/client/requests/CharterGetRequest.d.ts +8 -0
- package/api/resources/charters/client/requests/CharterGetRequest.js +3 -0
- package/api/resources/charters/client/requests/CharterPatchRequest.d.ts +67 -0
- package/api/resources/charters/client/requests/CharterPatchRequest.js +3 -0
- package/api/resources/charters/client/requests/index.d.ts +4 -0
- package/api/resources/charters/client/requests/index.js +2 -0
- package/api/resources/charters/exports.d.ts +2 -0
- package/api/resources/charters/exports.js +21 -0
- package/api/resources/charters/index.d.ts +1 -0
- package/api/resources/charters/index.js +1 -0
- package/api/resources/charters/types/CharterAncestorsResponse.d.ts +8 -0
- package/api/resources/charters/types/CharterAncestorsResponse.js +3 -0
- package/api/resources/charters/types/CharterBase.d.ts +14 -0
- package/api/resources/charters/types/CharterBase.js +3 -0
- package/api/resources/charters/types/CharterChildrenExclusionPolicy.d.ts +1 -1
- package/api/resources/charters/types/CharterChildrenExclusionPolicy.js +1 -1
- package/api/resources/charters/types/CharterChildrenGroup.d.ts +18 -0
- package/api/resources/charters/types/CharterChildrenGroup.js +3 -0
- package/api/resources/charters/types/CharterContent.d.ts +60 -0
- package/api/resources/charters/types/CharterContent.js +3 -0
- package/api/resources/charters/types/CharterKnowledgeBaseReference.d.ts +16 -0
- package/api/resources/charters/types/CharterKnowledgeBaseReference.js +3 -0
- package/api/resources/charters/types/CharterListChildrenRequest.d.ts +18 -0
- package/api/resources/charters/types/CharterListChildrenRequest.js +3 -0
- package/api/resources/charters/types/CharterListChildrenResponse.d.ts +55 -0
- package/api/resources/charters/types/CharterListChildrenResponse.js +3 -0
- package/api/resources/charters/types/CharterPatchReferences.d.ts +22 -0
- package/api/resources/charters/types/CharterPatchReferences.js +3 -0
- package/api/resources/charters/types/CharterReferences.d.ts +21 -0
- package/api/resources/charters/types/CharterReferences.js +3 -0
- package/api/resources/charters/types/CharterRequest.d.ts +36 -0
- package/api/resources/charters/types/CharterRequest.js +3 -0
- package/api/resources/charters/types/CharterResponse.d.ts +66 -0
- package/api/resources/charters/types/CharterResponse.js +3 -0
- package/api/resources/charters/types/CharterSearchField.d.ts +5 -0
- package/api/resources/charters/types/CharterSearchField.js +8 -0
- package/api/resources/charters/types/CharterSearchFilter.d.ts +15 -0
- package/api/resources/charters/types/CharterSearchFilter.js +3 -0
- package/api/resources/charters/types/CharterSearchRequest.d.ts +5 -0
- package/api/resources/charters/types/CharterSearchRequest.js +3 -0
- package/api/resources/charters/types/CharterSearchResponse.d.ts +36 -0
- package/api/resources/charters/types/CharterSearchResponse.js +3 -0
- package/api/resources/charters/types/CharterStatus.d.ts +2 -2
- package/api/resources/charters/types/CharterStatus.js +2 -2
- package/api/resources/charters/types/CharterSummary.d.ts +1 -9
- package/api/resources/charters/types/CharterType.d.ts +4 -4
- package/api/resources/charters/types/CharterType.js +4 -4
- package/api/resources/charters/types/index.d.ts +15 -0
- package/api/resources/charters/types/index.js +15 -0
- package/api/resources/commons/errors/BadRequestError.d.ts +1 -0
- package/api/resources/commons/errors/BadRequestError.js +1 -1
- package/api/resources/commons/errors/NotFoundError.d.ts +1 -0
- package/api/resources/commons/errors/NotFoundError.js +1 -1
- package/api/resources/commons/errors/PayloadTooLargeError.d.ts +1 -0
- package/api/resources/commons/errors/PayloadTooLargeError.js +1 -1
- package/api/resources/commons/errors/ServerError.d.ts +1 -0
- package/api/resources/commons/errors/ServerError.js +1 -1
- package/api/resources/commons/errors/TooManyRequestsError.d.ts +1 -0
- package/api/resources/commons/errors/TooManyRequestsError.js +1 -1
- package/api/resources/commons/types/AskType.d.ts +2 -2
- package/api/resources/commons/types/AskType.js +2 -2
- package/api/resources/commons/types/BotObjectResponse.d.ts +1 -1
- package/api/resources/commons/types/ConversationRound.d.ts +1 -1
- package/api/resources/commons/types/ConversationRound.js +1 -1
- package/api/resources/commons/types/IntelligentFieldPrecondition.d.ts +0 -4
- package/api/resources/commons/types/LlmPersona.d.ts +1 -1
- package/api/resources/commons/types/LlmPersona.js +1 -1
- package/api/resources/commons/types/MetadataComparisonCondition.d.ts +10 -0
- package/api/resources/commons/types/MetadataComparisonCondition.js +3 -0
- package/api/resources/commons/types/MetadataComparisonOperator.d.ts +22 -0
- package/api/resources/commons/types/MetadataComparisonOperator.js +25 -0
- package/api/resources/commons/types/MetadataCondition.d.ts +21 -0
- package/api/resources/commons/types/MetadataCondition.js +3 -0
- package/api/resources/commons/types/MetadataEntryCondition.d.ts +10 -0
- package/api/resources/commons/types/MetadataEntryCondition.js +3 -0
- package/api/resources/commons/types/MetadataFilter.d.ts +41 -0
- package/api/resources/commons/types/MetadataFilter.js +3 -0
- package/api/resources/commons/types/MetadataFilterGroup.d.ts +14 -0
- package/api/resources/commons/types/MetadataFilterGroup.js +3 -0
- package/api/resources/commons/types/SimulationContext.d.ts +2 -2
- package/api/resources/commons/types/SystemEventName.d.ts +3 -0
- package/api/resources/commons/types/SystemEventName.js +3 -0
- package/api/resources/commons/types/index.d.ts +6 -0
- package/api/resources/commons/types/index.js +6 -0
- package/api/resources/conversation/client/Client.d.ts +32 -0
- package/api/resources/conversation/client/Client.js +48 -17
- package/api/resources/conversation/types/AskRequest.d.ts +10 -10
- package/api/resources/conversation/types/ConversationFilter.d.ts +6 -1
- package/api/resources/customers/client/Client.d.ts +8 -0
- package/api/resources/customers/client/Client.js +12 -3
- package/api/resources/events/client/Client.d.ts +8 -0
- package/api/resources/events/client/Client.js +12 -3
- package/api/resources/inbox/client/Client.d.ts +16 -0
- package/api/resources/inbox/client/Client.js +22 -5
- package/api/resources/index.d.ts +1 -0
- package/api/resources/index.js +1 -0
- package/api/resources/integrations/client/Client.d.ts +2 -0
- package/api/resources/integrations/client/Client.js +4 -1
- package/api/resources/intelligentFields/client/Client.d.ts +28 -3
- package/api/resources/intelligentFields/client/Client.js +36 -8
- package/api/resources/intelligentFields/client/requests/IntelligentFieldGetRequest.d.ts +4 -0
- package/api/resources/intelligentFields/client/requests/IntelligentFieldPatchRequest.d.ts +13 -4
- package/api/resources/intelligentFields/types/EnumOption.d.ts +3 -1
- package/api/resources/intelligentFields/types/IntelligentFieldBase.d.ts +1 -1
- package/api/resources/intelligentFields/types/IntelligentFieldCore.d.ts +12 -11
- package/api/resources/intelligentFields/types/IntelligentFieldDetailResponse.d.ts +4 -1
- package/api/resources/intelligentFields/types/IntelligentFieldRequest.d.ts +4 -1
- package/api/resources/intelligentFields/types/IntelligentFieldStatus.d.ts +8 -1
- package/api/resources/intelligentFields/types/IntelligentFieldStatus.js +8 -1
- package/api/resources/intelligentFields/types/IntelligentFieldType.d.ts +10 -0
- package/api/resources/intelligentFields/types/IntelligentFieldType.js +10 -0
- package/api/resources/knowledge/client/Client.d.ts +32 -0
- package/api/resources/knowledge/client/Client.js +47 -16
- package/api/resources/knowledge/types/KnowledgeDocumentFilter.d.ts +13 -0
- package/api/resources/knowledge/types/KnowledgeDocumentRequest.d.ts +4 -2
- package/api/resources/knowledge/types/KnowledgeDocumentResponse.d.ts +33 -9
- package/api/resources/knowledge/types/KnowledgeDocumentSearchResponse.d.ts +7 -1
- package/api/resources/organizations/client/Client.d.ts +12 -0
- package/api/resources/organizations/client/Client.js +17 -4
- package/api/resources/segments/client/Client.d.ts +10 -0
- package/api/resources/segments/client/Client.js +14 -3
- package/api/resources/translations/client/Client.d.ts +2 -0
- package/api/resources/translations/client/Client.js +4 -1
- package/api/resources/triggers/client/Client.d.ts +10 -0
- package/api/resources/triggers/client/Client.js +14 -3
- package/api/resources/users/client/Client.d.ts +10 -0
- package/api/resources/users/client/Client.js +13 -2
- package/api/resources/voice/client/Client.d.ts +2 -0
- package/api/resources/voice/client/Client.js +4 -1
- package/api/resources/voiceConversations/client/Client.d.ts +4 -1
- package/api/resources/voiceConversations/client/Client.js +2 -1
- package/api/resources/voiceConversations/client/Socket.d.ts +11 -0
- package/api/resources/voiceConversations/client/Socket.js +15 -0
- package/core/fetcher/Fetcher.js +9 -92
- package/core/fetcher/getResponseBody.js +11 -0
- package/core/fetcher/makePassthroughRequest.js +26 -4
- package/core/fetcher/redactUrl.d.ts +2 -0
- package/core/fetcher/redactUrl.js +88 -0
- package/core/fetcher/signals.js +9 -1
- package/core/file/file.js +3 -0
- package/core/form-data-utils/FormDataWrapper.js +3 -0
- package/core/requestBody.d.ts +12 -0
- package/core/requestBody.js +26 -0
- package/core/runtime/index.d.ts +1 -1
- package/core/runtime/index.js +2 -1
- package/core/runtime/runtime.d.ts +19 -0
- package/core/runtime/runtime.js +74 -2
- package/core/schemas/builders/schema-utils/JsonError.js +2 -2
- package/core/schemas/builders/schema-utils/ParseError.js +2 -2
- package/core/stream/Stream.d.ts +45 -1
- package/core/stream/Stream.js +323 -84
- package/core/stream/index.d.ts +1 -0
- package/core/url/qs.js +2 -2
- package/core/websocket/ws.d.ts +6 -0
- package/core/websocket/ws.js +14 -1
- package/errors/MavenAGIError.d.ts +1 -0
- package/errors/MavenAGIError.js +5 -1
- package/errors/MavenAGITimeoutError.d.ts +2 -2
- package/errors/MavenAGITimeoutError.js +40 -6
- package/package.json +2 -2
- package/reference.md +587 -3
- package/serialization/resources/charters/client/index.d.ts +1 -0
- package/serialization/resources/charters/client/index.js +17 -0
- package/serialization/resources/charters/client/requests/CharterPatchRequest.d.ts +24 -0
- package/serialization/resources/charters/client/requests/CharterPatchRequest.js +57 -0
- package/serialization/resources/charters/client/requests/index.d.ts +1 -0
- package/serialization/resources/charters/client/requests/index.js +5 -0
- package/serialization/resources/charters/index.d.ts +1 -0
- package/serialization/resources/charters/index.js +1 -0
- package/serialization/resources/charters/types/CharterAncestorsResponse.d.ts +10 -0
- package/serialization/resources/charters/types/CharterAncestorsResponse.js +42 -0
- package/serialization/resources/charters/types/CharterBase.d.ts +11 -0
- package/serialization/resources/charters/types/CharterBase.js +43 -0
- package/serialization/resources/charters/types/CharterChildrenGroup.d.ts +13 -0
- package/serialization/resources/charters/types/CharterChildrenGroup.js +45 -0
- package/serialization/resources/charters/types/CharterContent.d.ts +19 -0
- package/serialization/resources/charters/types/CharterContent.js +54 -0
- package/serialization/resources/charters/types/CharterKnowledgeBaseReference.d.ts +11 -0
- package/serialization/resources/charters/types/CharterKnowledgeBaseReference.js +44 -0
- package/serialization/resources/charters/types/CharterListChildrenRequest.d.ts +11 -0
- package/serialization/resources/charters/types/CharterListChildrenRequest.js +45 -0
- package/serialization/resources/charters/types/CharterListChildrenResponse.d.ts +11 -0
- package/serialization/resources/charters/types/CharterListChildrenResponse.js +45 -0
- package/serialization/resources/charters/types/CharterPatchReferences.d.ts +12 -0
- package/serialization/resources/charters/types/CharterPatchReferences.js +44 -0
- package/serialization/resources/charters/types/CharterReferences.d.ts +12 -0
- package/serialization/resources/charters/types/CharterReferences.js +44 -0
- package/serialization/resources/charters/types/CharterRequest.d.ts +13 -0
- package/serialization/resources/charters/types/CharterRequest.js +47 -0
- package/serialization/resources/charters/types/CharterResponse.d.ts +25 -0
- package/serialization/resources/charters/types/CharterResponse.js +60 -0
- package/serialization/resources/charters/types/CharterSearchField.d.ts +7 -0
- package/serialization/resources/charters/types/CharterSearchField.js +39 -0
- package/serialization/resources/charters/types/CharterSearchFilter.d.ts +11 -0
- package/serialization/resources/charters/types/CharterSearchFilter.js +43 -0
- package/serialization/resources/charters/types/CharterSearchRequest.d.ts +13 -0
- package/serialization/resources/charters/types/CharterSearchRequest.js +47 -0
- package/serialization/resources/charters/types/CharterSearchResponse.d.ts +11 -0
- package/serialization/resources/charters/types/CharterSearchResponse.js +45 -0
- package/serialization/resources/charters/types/CharterSummary.d.ts +0 -2
- package/serialization/resources/charters/types/CharterSummary.js +0 -2
- package/serialization/resources/charters/types/index.d.ts +15 -0
- package/serialization/resources/charters/types/index.js +15 -0
- package/serialization/resources/commons/types/MetadataComparisonCondition.d.ts +11 -0
- package/serialization/resources/commons/types/MetadataComparisonCondition.js +43 -0
- package/serialization/resources/commons/types/MetadataComparisonOperator.d.ts +7 -0
- package/serialization/resources/commons/types/MetadataComparisonOperator.js +39 -0
- package/serialization/resources/commons/types/MetadataCondition.d.ts +19 -0
- package/serialization/resources/commons/types/MetadataCondition.js +51 -0
- package/serialization/resources/commons/types/MetadataEntryCondition.d.ts +11 -0
- package/serialization/resources/commons/types/MetadataEntryCondition.js +43 -0
- package/serialization/resources/commons/types/MetadataFilter.d.ts +14 -0
- package/serialization/resources/commons/types/MetadataFilter.js +49 -0
- package/serialization/resources/commons/types/MetadataFilterGroup.d.ts +11 -0
- package/serialization/resources/commons/types/MetadataFilterGroup.js +44 -0
- package/serialization/resources/commons/types/SystemEventName.d.ts +1 -1
- package/serialization/resources/commons/types/SystemEventName.js +1 -0
- package/serialization/resources/commons/types/index.d.ts +6 -0
- package/serialization/resources/commons/types/index.js +6 -0
- package/serialization/resources/index.d.ts +1 -0
- package/serialization/resources/index.js +1 -0
- package/serialization/resources/intelligentFields/client/requests/IntelligentFieldPatchRequest.d.ts +1 -0
- package/serialization/resources/intelligentFields/client/requests/IntelligentFieldPatchRequest.js +1 -0
- package/serialization/resources/knowledge/types/KnowledgeDocumentFilter.d.ts +2 -0
- package/serialization/resources/knowledge/types/KnowledgeDocumentFilter.js +2 -0
- package/serialization/resources/knowledge/types/KnowledgeDocumentResponse.d.ts +0 -2
- package/serialization/resources/knowledge/types/KnowledgeDocumentResponse.js +0 -2
- package/serialization/resources/knowledge/types/KnowledgeDocumentSearchResponse.d.ts +2 -0
- package/serialization/resources/knowledge/types/KnowledgeDocumentSearchResponse.js +2 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -56,7 +56,7 @@ class VoiceConversationsClient {
|
|
|
56
56
|
connect(args) {
|
|
57
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
58
|
var _a, _b, _c;
|
|
59
|
-
const { version, protocols, queryParams, headers, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal, } = args;
|
|
59
|
+
const { version, protocols, queryParams, headers, debug, reconnectAttempts, connectionTimeoutInSeconds, abortSignal, shouldReconnect, } = args;
|
|
60
60
|
const _queryParams = {
|
|
61
61
|
version,
|
|
62
62
|
};
|
|
@@ -71,6 +71,7 @@ class VoiceConversationsClient {
|
|
|
71
71
|
debug: debug !== null && debug !== void 0 ? debug : false,
|
|
72
72
|
maxRetries: reconnectAttempts !== null && reconnectAttempts !== void 0 ? reconnectAttempts : 30,
|
|
73
73
|
connectionTimeout: connectionTimeoutInSeconds != null ? connectionTimeoutInSeconds * 1000 : undefined,
|
|
74
|
+
shouldReconnect,
|
|
74
75
|
},
|
|
75
76
|
abortSignal: abortSignal,
|
|
76
77
|
});
|
|
@@ -33,6 +33,17 @@ export declare class VoiceConversationsSocket {
|
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
35
|
on<T extends keyof VoiceConversationsSocket.EventHandlers>(event: T, callback: VoiceConversationsSocket.EventHandlers[T]): void;
|
|
36
|
+
/**
|
|
37
|
+
* @param event - The event to detach from.
|
|
38
|
+
* @param callback - The callback previously registered with `on`. No-op if it is not the callback currently registered for this event.
|
|
39
|
+
* Usage:
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const handler = () => console.log('The websocket is open');
|
|
42
|
+
* this.on('open', handler);
|
|
43
|
+
* this.off('open', handler);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
off<T extends keyof VoiceConversationsSocket.EventHandlers>(event: T, callback: VoiceConversationsSocket.EventHandlers[T]): void;
|
|
36
47
|
sendConfig(message: MavenAGI.Config): void;
|
|
37
48
|
sendUserAudioChunk(message: MavenAGI.UserAudioChunk): void;
|
|
38
49
|
/** Connect to the websocket and register event handlers. */
|
|
@@ -103,6 +103,21 @@ class VoiceConversationsSocket {
|
|
|
103
103
|
on(event, callback) {
|
|
104
104
|
this.eventHandlers[event] = callback;
|
|
105
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* @param event - The event to detach from.
|
|
108
|
+
* @param callback - The callback previously registered with `on`. No-op if it is not the callback currently registered for this event.
|
|
109
|
+
* Usage:
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const handler = () => console.log('The websocket is open');
|
|
112
|
+
* this.on('open', handler);
|
|
113
|
+
* this.off('open', handler);
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
off(event, callback) {
|
|
117
|
+
if (this.eventHandlers[event] === callback) {
|
|
118
|
+
delete this.eventHandlers[event];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
106
121
|
sendConfig(message) {
|
|
107
122
|
this.assertSocketIsOpen();
|
|
108
123
|
const jsonPayload = Config_1.Config.jsonOrThrow(message, {
|
package/core/fetcher/Fetcher.js
CHANGED
|
@@ -22,6 +22,7 @@ const getResponseBody_1 = require("./getResponseBody");
|
|
|
22
22
|
const Headers_1 = require("./Headers");
|
|
23
23
|
const makeRequest_1 = require("./makeRequest");
|
|
24
24
|
const RawResponse_1 = require("./RawResponse");
|
|
25
|
+
const redactUrl_1 = require("./redactUrl");
|
|
25
26
|
const requestWithRetries_1 = require("./requestWithRetries");
|
|
26
27
|
const SENSITIVE_HEADERS = new Set([
|
|
27
28
|
"authorization",
|
|
@@ -53,100 +54,16 @@ function redactHeaders(headers) {
|
|
|
53
54
|
}
|
|
54
55
|
return filtered;
|
|
55
56
|
}
|
|
56
|
-
const SENSITIVE_QUERY_PARAMS = new Set([
|
|
57
|
-
"api_key",
|
|
58
|
-
"api-key",
|
|
59
|
-
"apikey",
|
|
60
|
-
"token",
|
|
61
|
-
"access_token",
|
|
62
|
-
"access-token",
|
|
63
|
-
"auth_token",
|
|
64
|
-
"auth-token",
|
|
65
|
-
"password",
|
|
66
|
-
"passwd",
|
|
67
|
-
"secret",
|
|
68
|
-
"api_secret",
|
|
69
|
-
"api-secret",
|
|
70
|
-
"apisecret",
|
|
71
|
-
"key",
|
|
72
|
-
"session",
|
|
73
|
-
"session_id",
|
|
74
|
-
"session-id",
|
|
75
|
-
]);
|
|
76
57
|
function redactQueryParameters(queryParameters) {
|
|
77
58
|
if (queryParameters == null) {
|
|
78
59
|
return undefined;
|
|
79
60
|
}
|
|
80
61
|
const redacted = {};
|
|
81
62
|
for (const [key, value] of Object.entries(queryParameters)) {
|
|
82
|
-
redacted[key] = SENSITIVE_QUERY_PARAMS.has(key.toLowerCase()) ? "[REDACTED]" : value;
|
|
63
|
+
redacted[key] = redactUrl_1.SENSITIVE_QUERY_PARAMS.has(key.toLowerCase()) ? "[REDACTED]" : value;
|
|
83
64
|
}
|
|
84
65
|
return redacted;
|
|
85
66
|
}
|
|
86
|
-
function redactUrl(url) {
|
|
87
|
-
const protocolIndex = url.indexOf("://");
|
|
88
|
-
if (protocolIndex === -1)
|
|
89
|
-
return url;
|
|
90
|
-
const afterProtocol = protocolIndex + 3;
|
|
91
|
-
// Find the first delimiter that marks the end of the authority section
|
|
92
|
-
const pathStart = url.indexOf("/", afterProtocol);
|
|
93
|
-
let queryStart = url.indexOf("?", afterProtocol);
|
|
94
|
-
let fragmentStart = url.indexOf("#", afterProtocol);
|
|
95
|
-
const firstDelimiter = Math.min(pathStart === -1 ? url.length : pathStart, queryStart === -1 ? url.length : queryStart, fragmentStart === -1 ? url.length : fragmentStart);
|
|
96
|
-
// Find the LAST @ before the delimiter (handles multiple @ in credentials)
|
|
97
|
-
let atIndex = -1;
|
|
98
|
-
for (let i = afterProtocol; i < firstDelimiter; i++) {
|
|
99
|
-
if (url[i] === "@") {
|
|
100
|
-
atIndex = i;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (atIndex !== -1) {
|
|
104
|
-
url = `${url.slice(0, afterProtocol)}[REDACTED]@${url.slice(atIndex + 1)}`;
|
|
105
|
-
}
|
|
106
|
-
// Recalculate queryStart since url might have changed
|
|
107
|
-
queryStart = url.indexOf("?");
|
|
108
|
-
if (queryStart === -1)
|
|
109
|
-
return url;
|
|
110
|
-
fragmentStart = url.indexOf("#", queryStart);
|
|
111
|
-
const queryEnd = fragmentStart !== -1 ? fragmentStart : url.length;
|
|
112
|
-
const queryString = url.slice(queryStart + 1, queryEnd);
|
|
113
|
-
if (queryString.length === 0)
|
|
114
|
-
return url;
|
|
115
|
-
// FAST PATH: Quick check if any sensitive keywords present
|
|
116
|
-
// Using indexOf is faster than regex for simple substring matching
|
|
117
|
-
const lower = queryString.toLowerCase();
|
|
118
|
-
const hasSensitive = lower.includes("token") ||
|
|
119
|
-
lower.includes("key") ||
|
|
120
|
-
lower.includes("password") ||
|
|
121
|
-
lower.includes("passwd") ||
|
|
122
|
-
lower.includes("secret") ||
|
|
123
|
-
lower.includes("session") ||
|
|
124
|
-
lower.includes("auth");
|
|
125
|
-
if (!hasSensitive) {
|
|
126
|
-
return url;
|
|
127
|
-
}
|
|
128
|
-
// SLOW PATH: Parse and redact
|
|
129
|
-
const redactedParams = [];
|
|
130
|
-
const params = queryString.split("&");
|
|
131
|
-
for (const param of params) {
|
|
132
|
-
const equalIndex = param.indexOf("=");
|
|
133
|
-
if (equalIndex === -1) {
|
|
134
|
-
redactedParams.push(param);
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
const key = param.slice(0, equalIndex);
|
|
138
|
-
let shouldRedact = SENSITIVE_QUERY_PARAMS.has(key.toLowerCase());
|
|
139
|
-
if (!shouldRedact && key.includes("%")) {
|
|
140
|
-
try {
|
|
141
|
-
const decodedKey = decodeURIComponent(key);
|
|
142
|
-
shouldRedact = SENSITIVE_QUERY_PARAMS.has(decodedKey.toLowerCase());
|
|
143
|
-
}
|
|
144
|
-
catch (_a) { }
|
|
145
|
-
}
|
|
146
|
-
redactedParams.push(shouldRedact ? `${key}=[REDACTED]` : param);
|
|
147
|
-
}
|
|
148
|
-
return url.slice(0, queryStart + 1) + redactedParams.join("&") + url.slice(queryEnd);
|
|
149
|
-
}
|
|
150
67
|
function getHeaders(args) {
|
|
151
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
152
69
|
var _a;
|
|
@@ -198,7 +115,7 @@ function fetcherImpl(args) {
|
|
|
198
115
|
if (logger.isDebug()) {
|
|
199
116
|
const metadata = {
|
|
200
117
|
method: args.method,
|
|
201
|
-
url: redactUrl(url),
|
|
118
|
+
url: (0, redactUrl_1.redactUrl)(url),
|
|
202
119
|
headers: redactHeaders(headers),
|
|
203
120
|
queryParameters: redactQueryParameters(args.queryParameters),
|
|
204
121
|
hasBody: requestBody != null,
|
|
@@ -213,7 +130,7 @@ function fetcherImpl(args) {
|
|
|
213
130
|
if (logger.isDebug()) {
|
|
214
131
|
const metadata = {
|
|
215
132
|
method: args.method,
|
|
216
|
-
url: redactUrl(url),
|
|
133
|
+
url: (0, redactUrl_1.redactUrl)(url),
|
|
217
134
|
statusCode: response.status,
|
|
218
135
|
responseHeaders: redactHeaders(response.headers),
|
|
219
136
|
};
|
|
@@ -231,7 +148,7 @@ function fetcherImpl(args) {
|
|
|
231
148
|
if (logger.isError()) {
|
|
232
149
|
const metadata = {
|
|
233
150
|
method: args.method,
|
|
234
|
-
url: redactUrl(url),
|
|
151
|
+
url: (0, redactUrl_1.redactUrl)(url),
|
|
235
152
|
statusCode: response.status,
|
|
236
153
|
responseHeaders: redactHeaders(Object.fromEntries(response.headers.entries())),
|
|
237
154
|
};
|
|
@@ -253,7 +170,7 @@ function fetcherImpl(args) {
|
|
|
253
170
|
if (logger.isError()) {
|
|
254
171
|
const metadata = {
|
|
255
172
|
method: args.method,
|
|
256
|
-
url: redactUrl(url),
|
|
173
|
+
url: (0, redactUrl_1.redactUrl)(url),
|
|
257
174
|
};
|
|
258
175
|
logger.error("HTTP request was aborted", metadata);
|
|
259
176
|
}
|
|
@@ -271,7 +188,7 @@ function fetcherImpl(args) {
|
|
|
271
188
|
if (logger.isError()) {
|
|
272
189
|
const metadata = {
|
|
273
190
|
method: args.method,
|
|
274
|
-
url: redactUrl(url),
|
|
191
|
+
url: (0, redactUrl_1.redactUrl)(url),
|
|
275
192
|
timeoutMs: args.timeoutMs,
|
|
276
193
|
};
|
|
277
194
|
logger.error("HTTP request timed out", metadata);
|
|
@@ -289,7 +206,7 @@ function fetcherImpl(args) {
|
|
|
289
206
|
if (logger.isError()) {
|
|
290
207
|
const metadata = {
|
|
291
208
|
method: args.method,
|
|
292
|
-
url: redactUrl(url),
|
|
209
|
+
url: (0, redactUrl_1.redactUrl)(url),
|
|
293
210
|
errorMessage: error.message,
|
|
294
211
|
};
|
|
295
212
|
logger.error("HTTP request failed with error", metadata);
|
|
@@ -307,7 +224,7 @@ function fetcherImpl(args) {
|
|
|
307
224
|
if (logger.isError()) {
|
|
308
225
|
const metadata = {
|
|
309
226
|
method: args.method,
|
|
310
|
-
url: redactUrl(url),
|
|
227
|
+
url: (0, redactUrl_1.redactUrl)(url),
|
|
311
228
|
error: (0, json_1.toJson)(error),
|
|
312
229
|
};
|
|
313
230
|
logger.error("HTTP request failed with unknown error", metadata);
|
|
@@ -12,6 +12,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.getResponseBody = getResponseBody;
|
|
13
13
|
const json_1 = require("../json");
|
|
14
14
|
const BinaryResponse_1 = require("./BinaryResponse");
|
|
15
|
+
// Pins the upstream Response so undici's FinalizationRegistry can't GC it and cancel the body stream.
|
|
16
|
+
function retainResponse(target, response) {
|
|
17
|
+
Object.defineProperty(target, "__fern_response_ref", {
|
|
18
|
+
value: response,
|
|
19
|
+
enumerable: false,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: false,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
15
24
|
function getResponseBody(response, responseType) {
|
|
16
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
26
|
switch (responseType) {
|
|
@@ -31,6 +40,7 @@ function getResponseBody(response, responseType) {
|
|
|
31
40
|
},
|
|
32
41
|
};
|
|
33
42
|
}
|
|
43
|
+
retainResponse(response.body, response);
|
|
34
44
|
return response.body;
|
|
35
45
|
case "streaming":
|
|
36
46
|
if (response.body == null) {
|
|
@@ -42,6 +52,7 @@ function getResponseBody(response, responseType) {
|
|
|
42
52
|
},
|
|
43
53
|
};
|
|
44
54
|
}
|
|
55
|
+
retainResponse(response.body, response);
|
|
45
56
|
return response.body;
|
|
46
57
|
case "text":
|
|
47
58
|
return yield response.text();
|
|
@@ -15,6 +15,7 @@ const join_1 = require("../url/join");
|
|
|
15
15
|
const EndpointSupplier_1 = require("./EndpointSupplier");
|
|
16
16
|
const getFetchFn_1 = require("./getFetchFn");
|
|
17
17
|
const makeRequest_1 = require("./makeRequest");
|
|
18
|
+
const redactUrl_1 = require("./redactUrl");
|
|
18
19
|
const requestWithRetries_1 = require("./requestWithRetries");
|
|
19
20
|
const Supplier_1 = require("./Supplier");
|
|
20
21
|
/**
|
|
@@ -79,8 +80,10 @@ function makePassthroughRequest(input, init, clientOptions, requestOptions) {
|
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
|
-
// Apply auth headers
|
|
83
|
-
|
|
83
|
+
// Apply auth headers, but only when the resolved URL targets the configured base URL.
|
|
84
|
+
// This prevents the SDK's credentials from leaking to an unrelated host when a caller
|
|
85
|
+
// passes an absolute cross-origin URL into the passthrough fetch escape hatch.
|
|
86
|
+
if (clientOptions.getAuthHeaders != null && targetsBaseUrl(fullUrl, baseUrl)) {
|
|
84
87
|
const authHeaders = yield clientOptions.getAuthHeaders();
|
|
85
88
|
for (const [key, value] of Object.entries(authHeaders)) {
|
|
86
89
|
mergedHeaders[key.toLowerCase()] = value;
|
|
@@ -115,7 +118,7 @@ function makePassthroughRequest(input, init, clientOptions, requestOptions) {
|
|
|
115
118
|
if (logger.isDebug()) {
|
|
116
119
|
logger.debug("Making passthrough HTTP request", {
|
|
117
120
|
method,
|
|
118
|
-
url: fullUrl,
|
|
121
|
+
url: (0, redactUrl_1.redactUrl)(fullUrl),
|
|
119
122
|
hasBody: body != null,
|
|
120
123
|
});
|
|
121
124
|
}
|
|
@@ -126,10 +129,29 @@ function makePassthroughRequest(input, init, clientOptions, requestOptions) {
|
|
|
126
129
|
if (logger.isDebug()) {
|
|
127
130
|
logger.debug("Passthrough HTTP request completed", {
|
|
128
131
|
method,
|
|
129
|
-
url: fullUrl,
|
|
132
|
+
url: (0, redactUrl_1.redactUrl)(fullUrl),
|
|
130
133
|
statusCode: response.status,
|
|
131
134
|
});
|
|
132
135
|
}
|
|
133
136
|
return response;
|
|
134
137
|
});
|
|
135
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Returns true when the resolved request URL points at the same origin as the
|
|
141
|
+
* configured base URL. Relative paths are always joined onto the base URL, so
|
|
142
|
+
* they resolve to the base origin and return true. Absolute URLs only match when
|
|
143
|
+
* their origin equals the base origin. When there is no base URL to compare
|
|
144
|
+
* against, or either value is not a parseable absolute URL, this returns false so
|
|
145
|
+
* auth headers are not attached.
|
|
146
|
+
*/
|
|
147
|
+
function targetsBaseUrl(fullUrl, baseUrl) {
|
|
148
|
+
if (baseUrl == null) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
return new URL(fullUrl).origin === new URL(baseUrl).origin;
|
|
153
|
+
}
|
|
154
|
+
catch (_a) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SENSITIVE_QUERY_PARAMS = void 0;
|
|
4
|
+
exports.redactUrl = redactUrl;
|
|
5
|
+
exports.SENSITIVE_QUERY_PARAMS = new Set([
|
|
6
|
+
"api_key",
|
|
7
|
+
"api-key",
|
|
8
|
+
"apikey",
|
|
9
|
+
"token",
|
|
10
|
+
"access_token",
|
|
11
|
+
"access-token",
|
|
12
|
+
"auth_token",
|
|
13
|
+
"auth-token",
|
|
14
|
+
"password",
|
|
15
|
+
"passwd",
|
|
16
|
+
"secret",
|
|
17
|
+
"api_secret",
|
|
18
|
+
"api-secret",
|
|
19
|
+
"apisecret",
|
|
20
|
+
"key",
|
|
21
|
+
"session",
|
|
22
|
+
"session_id",
|
|
23
|
+
"session-id",
|
|
24
|
+
]);
|
|
25
|
+
function redactUrl(url) {
|
|
26
|
+
const protocolIndex = url.indexOf("://");
|
|
27
|
+
if (protocolIndex === -1)
|
|
28
|
+
return url;
|
|
29
|
+
const afterProtocol = protocolIndex + 3;
|
|
30
|
+
// Find the first delimiter that marks the end of the authority section
|
|
31
|
+
const pathStart = url.indexOf("/", afterProtocol);
|
|
32
|
+
let queryStart = url.indexOf("?", afterProtocol);
|
|
33
|
+
let fragmentStart = url.indexOf("#", afterProtocol);
|
|
34
|
+
const firstDelimiter = Math.min(pathStart === -1 ? url.length : pathStart, queryStart === -1 ? url.length : queryStart, fragmentStart === -1 ? url.length : fragmentStart);
|
|
35
|
+
// Find the LAST @ before the delimiter (handles multiple @ in credentials)
|
|
36
|
+
let atIndex = -1;
|
|
37
|
+
for (let i = afterProtocol; i < firstDelimiter; i++) {
|
|
38
|
+
if (url[i] === "@") {
|
|
39
|
+
atIndex = i;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (atIndex !== -1) {
|
|
43
|
+
url = `${url.slice(0, afterProtocol)}[REDACTED]@${url.slice(atIndex + 1)}`;
|
|
44
|
+
}
|
|
45
|
+
// Recalculate queryStart since url might have changed
|
|
46
|
+
queryStart = url.indexOf("?");
|
|
47
|
+
if (queryStart === -1)
|
|
48
|
+
return url;
|
|
49
|
+
fragmentStart = url.indexOf("#", queryStart);
|
|
50
|
+
const queryEnd = fragmentStart !== -1 ? fragmentStart : url.length;
|
|
51
|
+
const queryString = url.slice(queryStart + 1, queryEnd);
|
|
52
|
+
if (queryString.length === 0)
|
|
53
|
+
return url;
|
|
54
|
+
// FAST PATH: Quick check if any sensitive keywords present
|
|
55
|
+
// Using indexOf is faster than regex for simple substring matching
|
|
56
|
+
const lower = queryString.toLowerCase();
|
|
57
|
+
const hasSensitive = lower.includes("token") ||
|
|
58
|
+
lower.includes("key") ||
|
|
59
|
+
lower.includes("password") ||
|
|
60
|
+
lower.includes("passwd") ||
|
|
61
|
+
lower.includes("secret") ||
|
|
62
|
+
lower.includes("session") ||
|
|
63
|
+
lower.includes("auth");
|
|
64
|
+
if (!hasSensitive) {
|
|
65
|
+
return url;
|
|
66
|
+
}
|
|
67
|
+
// SLOW PATH: Parse and redact
|
|
68
|
+
const redactedParams = [];
|
|
69
|
+
const params = queryString.split("&");
|
|
70
|
+
for (const param of params) {
|
|
71
|
+
const equalIndex = param.indexOf("=");
|
|
72
|
+
if (equalIndex === -1) {
|
|
73
|
+
redactedParams.push(param);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const key = param.slice(0, equalIndex);
|
|
77
|
+
let shouldRedact = exports.SENSITIVE_QUERY_PARAMS.has(key.toLowerCase());
|
|
78
|
+
if (!shouldRedact && key.includes("%")) {
|
|
79
|
+
try {
|
|
80
|
+
const decodedKey = decodeURIComponent(key);
|
|
81
|
+
shouldRedact = exports.SENSITIVE_QUERY_PARAMS.has(decodedKey.toLowerCase());
|
|
82
|
+
}
|
|
83
|
+
catch (_a) { }
|
|
84
|
+
}
|
|
85
|
+
redactedParams.push(shouldRedact ? `${key}=[REDACTED]` : param);
|
|
86
|
+
}
|
|
87
|
+
return url.slice(0, queryStart + 1) + redactedParams.join("&") + url.slice(queryEnd);
|
|
88
|
+
}
|
package/core/fetcher/signals.js
CHANGED
|
@@ -14,11 +14,19 @@ function anySignal(...args) {
|
|
|
14
14
|
for (const signal of signals) {
|
|
15
15
|
if (signal.aborted) {
|
|
16
16
|
controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason);
|
|
17
|
-
|
|
17
|
+
return controller.signal;
|
|
18
18
|
}
|
|
19
19
|
signal.addEventListener("abort", () => controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason), {
|
|
20
20
|
signal: controller.signal,
|
|
21
21
|
});
|
|
22
|
+
// Re-check after adding listener: the signal may have aborted
|
|
23
|
+
// between the initial `signal.aborted` check and the `addEventListener`
|
|
24
|
+
// call above. If it did, the abort event was already dispatched and
|
|
25
|
+
// the listener will never fire — we must manually abort.
|
|
26
|
+
if (signal.aborted) {
|
|
27
|
+
controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason);
|
|
28
|
+
return controller.signal;
|
|
29
|
+
}
|
|
22
30
|
}
|
|
23
31
|
return controller.signal;
|
|
24
32
|
}
|
package/core/file/file.js
CHANGED
|
@@ -78,6 +78,9 @@ function toMultipartDataPart(file) {
|
|
|
78
78
|
function getFileWithMetadata(file_1) {
|
|
79
79
|
return __awaiter(this, arguments, void 0, function* (file, { noSniffFileSize } = {}) {
|
|
80
80
|
var _a, _b, _c, _d, _e;
|
|
81
|
+
if (file == null) {
|
|
82
|
+
throw new Error(`Expected file to be a Blob, Buffer, ReadableStream, or an object with a "path" or "data" property, but received ${file === null ? "null" : "undefined"}.`);
|
|
83
|
+
}
|
|
81
84
|
if (isFileLike(file)) {
|
|
82
85
|
return getFileWithMetadata({
|
|
83
86
|
data: file,
|
|
@@ -73,6 +73,9 @@ class FormDataWrapper {
|
|
|
73
73
|
}
|
|
74
74
|
appendFile(key, value) {
|
|
75
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
if (value == null) {
|
|
77
|
+
throw new Error(`File upload for "${key}" received ${value === null ? "null" : "undefined"}. The generated code should not call appendFile with null/undefined — check that optional file fields are guarded before this call.`);
|
|
78
|
+
}
|
|
76
79
|
const { data, filename, contentType } = yield (0, index_1.toMultipartDataPart)(value);
|
|
77
80
|
const blob = yield convertToBlob(data, contentType);
|
|
78
81
|
if (filename) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spreads caller-supplied `additionalBodyParameters` (from `requestOptions.additionalBodyParameters`)
|
|
3
|
+
* on top of the request body. Caller-supplied properties win over the endpoint body. When no
|
|
4
|
+
* additional body parameters are provided, the original body is returned unchanged so serialization
|
|
5
|
+
* is unaffected.
|
|
6
|
+
*
|
|
7
|
+
* The merge only applies to plain-object (JSON object) bodies. When the body is `null`/`undefined`
|
|
8
|
+
* the additional parameters become the body; when the body is an array or a primitive JSON value it
|
|
9
|
+
* is returned unchanged, since object properties cannot be spread into it. This mirrors the Python
|
|
10
|
+
* SDK, which only merges additional body parameters into mapping bodies.
|
|
11
|
+
*/
|
|
12
|
+
export declare function mergeAdditionalBodyParameters(body: unknown, additionalBodyParameters: Record<string, unknown> | undefined): unknown;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeAdditionalBodyParameters = mergeAdditionalBodyParameters;
|
|
4
|
+
/**
|
|
5
|
+
* Spreads caller-supplied `additionalBodyParameters` (from `requestOptions.additionalBodyParameters`)
|
|
6
|
+
* on top of the request body. Caller-supplied properties win over the endpoint body. When no
|
|
7
|
+
* additional body parameters are provided, the original body is returned unchanged so serialization
|
|
8
|
+
* is unaffected.
|
|
9
|
+
*
|
|
10
|
+
* The merge only applies to plain-object (JSON object) bodies. When the body is `null`/`undefined`
|
|
11
|
+
* the additional parameters become the body; when the body is an array or a primitive JSON value it
|
|
12
|
+
* is returned unchanged, since object properties cannot be spread into it. This mirrors the Python
|
|
13
|
+
* SDK, which only merges additional body parameters into mapping bodies.
|
|
14
|
+
*/
|
|
15
|
+
function mergeAdditionalBodyParameters(body, additionalBodyParameters) {
|
|
16
|
+
if (additionalBodyParameters == null) {
|
|
17
|
+
return body;
|
|
18
|
+
}
|
|
19
|
+
if (body == null) {
|
|
20
|
+
return Object.assign({}, additionalBodyParameters);
|
|
21
|
+
}
|
|
22
|
+
if (typeof body === "object" && !Array.isArray(body)) {
|
|
23
|
+
return Object.assign(Object.assign({}, body), additionalBodyParameters);
|
|
24
|
+
}
|
|
25
|
+
return body;
|
|
26
|
+
}
|
package/core/runtime/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { RUNTIME } from "./runtime";
|
|
1
|
+
export { getUserAgent, RUNTIME } from "./runtime";
|
package/core/runtime/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RUNTIME = void 0;
|
|
3
|
+
exports.RUNTIME = exports.getUserAgent = void 0;
|
|
4
4
|
var runtime_1 = require("./runtime");
|
|
5
|
+
Object.defineProperty(exports, "getUserAgent", { enumerable: true, get: function () { return runtime_1.getUserAgent; } });
|
|
5
6
|
Object.defineProperty(exports, "RUNTIME", { enumerable: true, get: function () { return runtime_1.RUNTIME; } });
|
|
@@ -6,4 +6,23 @@ export interface Runtime {
|
|
|
6
6
|
type: "browser" | "web-worker" | "deno" | "bun" | "node" | "react-native" | "unknown" | "workerd" | "edge-runtime";
|
|
7
7
|
version?: string;
|
|
8
8
|
parsedVersion?: number;
|
|
9
|
+
/**
|
|
10
|
+
* The operating system the SDK is running on, when it can be determined
|
|
11
|
+
* (e.g. "linux", "darwin", "win32" on server runtimes). Undefined in
|
|
12
|
+
* environments where the OS is not observable (e.g. browsers).
|
|
13
|
+
*/
|
|
14
|
+
os?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The CPU architecture the SDK is running on, when it can be determined
|
|
17
|
+
* (e.g. "x64", "arm64" on server runtimes). Undefined in environments where
|
|
18
|
+
* the architecture is not observable (e.g. browsers).
|
|
19
|
+
*/
|
|
20
|
+
arch?: string;
|
|
9
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Builds a structured User-Agent string of the form
|
|
24
|
+
* `{sdkName}/{sdkVersion} ({os}; {arch}) {runtime}/{runtimeVersion}`
|
|
25
|
+
* where the platform group and runtime segment are omitted gracefully when the
|
|
26
|
+
* underlying values cannot be determined (e.g. in a browser).
|
|
27
|
+
*/
|
|
28
|
+
export declare function getUserAgent(sdkName: string, sdkVersion: string): string;
|
package/core/runtime/runtime.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RUNTIME = void 0;
|
|
4
|
+
exports.getUserAgent = getUserAgent;
|
|
4
5
|
/**
|
|
5
6
|
* A constant that indicates which environment and version the SDK is running in.
|
|
6
7
|
*/
|
|
7
8
|
exports.RUNTIME = evaluateRuntime();
|
|
8
9
|
function evaluateRuntime() {
|
|
9
|
-
var _a, _b, _c, _d, _e;
|
|
10
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
10
11
|
/**
|
|
11
12
|
* A constant that indicates whether the environment the code is running is a Web Browser.
|
|
12
13
|
*/
|
|
@@ -59,6 +60,8 @@ function evaluateRuntime() {
|
|
|
59
60
|
return {
|
|
60
61
|
type: "deno",
|
|
61
62
|
version: Deno.version.deno,
|
|
63
|
+
os: (_e = Deno.build) === null || _e === void 0 ? void 0 : _e.os,
|
|
64
|
+
arch: (_f = Deno.build) === null || _f === void 0 ? void 0 : _f.arch,
|
|
62
65
|
};
|
|
63
66
|
}
|
|
64
67
|
/**
|
|
@@ -69,6 +72,8 @@ function evaluateRuntime() {
|
|
|
69
72
|
return {
|
|
70
73
|
type: "bun",
|
|
71
74
|
version: Bun.version,
|
|
75
|
+
os: typeof process !== "undefined" ? process.platform : undefined,
|
|
76
|
+
arch: typeof process !== "undefined" ? process.arch : undefined,
|
|
72
77
|
};
|
|
73
78
|
}
|
|
74
79
|
/**
|
|
@@ -90,15 +95,82 @@ function evaluateRuntime() {
|
|
|
90
95
|
* Edge Runtime warns about Node.js APIs even when they are guarded).
|
|
91
96
|
*/
|
|
92
97
|
const _process = typeof process !== "undefined" ? process : undefined;
|
|
93
|
-
const isNode = typeof _process !== "undefined" && typeof ((
|
|
98
|
+
const isNode = typeof _process !== "undefined" && typeof ((_g = _process.versions) === null || _g === void 0 ? void 0 : _g.node) === "string";
|
|
94
99
|
if (isNode) {
|
|
95
100
|
return {
|
|
96
101
|
type: "node",
|
|
97
102
|
version: _process.versions.node,
|
|
98
103
|
parsedVersion: Number(_process.versions.node.split(".")[0]),
|
|
104
|
+
os: _process.platform,
|
|
105
|
+
arch: _process.arch,
|
|
99
106
|
};
|
|
100
107
|
}
|
|
101
108
|
return {
|
|
102
109
|
type: "unknown",
|
|
103
110
|
};
|
|
104
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Display names for the language runtimes whose version is meaningful to encode
|
|
114
|
+
* in a User-Agent. Environments where a version string is not useful (e.g.
|
|
115
|
+
* browsers, where `version` is the full navigator UA) are intentionally mapped
|
|
116
|
+
* to `undefined` so they are omitted from the User-Agent.
|
|
117
|
+
*/
|
|
118
|
+
const RUNTIME_DISPLAY_NAMES = {
|
|
119
|
+
node: "Node",
|
|
120
|
+
deno: "Deno",
|
|
121
|
+
bun: "Bun",
|
|
122
|
+
browser: undefined,
|
|
123
|
+
"web-worker": undefined,
|
|
124
|
+
"react-native": undefined,
|
|
125
|
+
workerd: undefined,
|
|
126
|
+
"edge-runtime": undefined,
|
|
127
|
+
unknown: undefined,
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* CPU architecture aliases that all refer to 64-bit x86. They are normalized to
|
|
131
|
+
* the single canonical token `x86_64` so the User-Agent architecture label is
|
|
132
|
+
* consistent regardless of which runtime reports it (Node reports `x64`, others
|
|
133
|
+
* report `amd64` or `x86_64`).
|
|
134
|
+
*/
|
|
135
|
+
const X86_64_ARCH_ALIASES = new Set(["x64", "amd64", "x86_64"]);
|
|
136
|
+
/**
|
|
137
|
+
* Normalizes a CPU architecture token, collapsing the 64-bit x86 aliases
|
|
138
|
+
* (`x64`, `amd64`, `x86_64`) to `x86_64`. Other architectures are returned
|
|
139
|
+
* unchanged.
|
|
140
|
+
*/
|
|
141
|
+
function normalizeArch(arch) {
|
|
142
|
+
if (arch == null) {
|
|
143
|
+
return arch;
|
|
144
|
+
}
|
|
145
|
+
return X86_64_ARCH_ALIASES.has(arch.toLowerCase()) ? "x86_64" : arch;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Percent-encodes the `@` and `/` characters in an npm package name so the
|
|
149
|
+
* User-Agent product token stays within the RFC 7230 token grammar. The
|
|
150
|
+
* original scoped package name can be recovered by URL-decoding (e.g.
|
|
151
|
+
* `@dummy/sdk` becomes `%40dummy%2Fsdk`).
|
|
152
|
+
*/
|
|
153
|
+
function encodeProductName(sdkName) {
|
|
154
|
+
return sdkName.replace(/@/g, "%40").replace(/\//g, "%2F");
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Builds a structured User-Agent string of the form
|
|
158
|
+
* `{sdkName}/{sdkVersion} ({os}; {arch}) {runtime}/{runtimeVersion}`
|
|
159
|
+
* where the platform group and runtime segment are omitted gracefully when the
|
|
160
|
+
* underlying values cannot be determined (e.g. in a browser).
|
|
161
|
+
*/
|
|
162
|
+
function getUserAgent(sdkName, sdkVersion) {
|
|
163
|
+
let userAgent = `${encodeProductName(sdkName)}/${sdkVersion}`;
|
|
164
|
+
const platform = [exports.RUNTIME.os, normalizeArch(exports.RUNTIME.arch)].filter((part) => part != null && part.length > 0);
|
|
165
|
+
if (platform.length > 0) {
|
|
166
|
+
userAgent += ` (${platform.join("; ")})`;
|
|
167
|
+
}
|
|
168
|
+
const runtimeName = RUNTIME_DISPLAY_NAMES[exports.RUNTIME.type];
|
|
169
|
+
if (runtimeName != null) {
|
|
170
|
+
userAgent += ` ${runtimeName}`;
|
|
171
|
+
if (exports.RUNTIME.version != null && exports.RUNTIME.version.length > 0) {
|
|
172
|
+
userAgent += `/${exports.RUNTIME.version}`;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return userAgent;
|
|
176
|
+
}
|
|
@@ -6,8 +6,8 @@ class JsonError extends Error {
|
|
|
6
6
|
constructor(errors) {
|
|
7
7
|
super(errors.map(stringifyValidationErrors_1.stringifyValidationError).join("; "));
|
|
8
8
|
this.errors = errors;
|
|
9
|
-
Object.setPrototypeOf(this,
|
|
10
|
-
this.name =
|
|
9
|
+
Object.setPrototypeOf(this, JsonError.prototype);
|
|
10
|
+
this.name = "JsonError";
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.JsonError = JsonError;
|