conjure-client
Advanced tools
Comparing version 2.6.0 to 2.7.0
@@ -39,3 +39,3 @@ /** | ||
userAgent: IUserAgent | IUserAgent[] | Array<Supplier<IUserAgent>>; | ||
token?: string | Supplier<string>; | ||
token?: string | Supplier<string> | Supplier<Promise<string>>; | ||
fetch?: FetchFunction; | ||
@@ -42,0 +42,0 @@ } |
@@ -182,38 +182,48 @@ "use strict"; | ||
FetchBridge.prototype.makeFetchCall = function (params) { | ||
var query = this.buildQueryString(params.queryArguments); | ||
var url = this.getBaseUrl() + "/" + this.buildPath(params) + (query.length > 0 ? "?" + query : ""); | ||
var data = params.data, _a = params.headers, headers = _a === void 0 ? {} : _a, method = params.method, requestMediaType = params.requestMediaType, responseMediaType = params.responseMediaType; | ||
var stringifiedHeaders = { | ||
"Fetch-User-Agent": this.getUserAgent().toString(), | ||
}; | ||
// Only send present headers as strings | ||
Object.keys(headers).forEach(function (key) { | ||
var headerValue = headers[key]; | ||
if (headerValue != null) { | ||
stringifiedHeaders[key] = headerValue.toString(); | ||
} | ||
return __awaiter(this, void 0, void 0, function () { | ||
var query, url, data, _a, headers, method, requestMediaType, responseMediaType, stringifiedHeaders, fetchRequestInit, token, fetchFunction; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
query = this.buildQueryString(params.queryArguments); | ||
url = this.getBaseUrl() + "/" + this.buildPath(params) + (query.length > 0 ? "?" + query : ""); | ||
data = params.data, _a = params.headers, headers = _a === void 0 ? {} : _a, method = params.method, requestMediaType = params.requestMediaType, responseMediaType = params.responseMediaType; | ||
stringifiedHeaders = { | ||
"Fetch-User-Agent": this.getUserAgent().toString(), | ||
}; | ||
// Only send present headers as strings | ||
Object.keys(headers).forEach(function (key) { | ||
var headerValue = headers[key]; | ||
if (headerValue != null) { | ||
stringifiedHeaders[key] = headerValue.toString(); | ||
} | ||
}); | ||
fetchRequestInit = { | ||
credentials: "same-origin", | ||
headers: stringifiedHeaders, | ||
method: method, | ||
}; | ||
return [4 /*yield*/, this.getToken()]; | ||
case 1: | ||
token = _b.sent(); | ||
if (token !== undefined) { | ||
fetchRequestInit.headers = __assign({}, fetchRequestInit.headers, { Authorization: "Bearer " + token }); | ||
} | ||
if (requestMediaType != null && requestMediaType !== httpApiBridge_1.MediaType.MULTIPART_FORM_DATA) { | ||
// don't include for form data because we need the browser to fill in the form boundary | ||
fetchRequestInit.headers["Content-Type"] = requestMediaType; | ||
} | ||
if (responseMediaType != null) { | ||
// If an endpoint can return multiple content types, make sure it returns the type that we're expecting | ||
// instead of the default `*/* | ||
fetchRequestInit.headers[FetchBridge.ACCEPT_HEADER] = responseMediaType; | ||
} | ||
if (data != null) { | ||
fetchRequestInit.body = this.handleBody(params); | ||
} | ||
fetchFunction = this.fetch || fetch; | ||
return [2 /*return*/, fetchFunction(url, fetchRequestInit)]; | ||
} | ||
}); | ||
}); | ||
var fetchRequestInit = { | ||
credentials: "same-origin", | ||
headers: stringifiedHeaders, | ||
method: method, | ||
}; | ||
var token = this.getToken(); | ||
if (token !== undefined) { | ||
fetchRequestInit.headers = __assign({}, fetchRequestInit.headers, { Authorization: "Bearer " + token }); | ||
} | ||
if (requestMediaType != null && requestMediaType !== httpApiBridge_1.MediaType.MULTIPART_FORM_DATA) { | ||
// don't include for form data because we need the browser to fill in the form boundary | ||
fetchRequestInit.headers["Content-Type"] = requestMediaType; | ||
} | ||
if (responseMediaType != null) { | ||
// If an endpoint can return multiple content types, make sure it returns the type that we're expecting | ||
// instead of the default `*/* | ||
fetchRequestInit.headers[FetchBridge.ACCEPT_HEADER] = responseMediaType; | ||
} | ||
if (data != null) { | ||
fetchRequestInit.body = this.handleBody(params); | ||
} | ||
var fetchFunction = this.fetch || fetch; | ||
return fetchFunction(url, fetchRequestInit); | ||
}; | ||
@@ -220,0 +230,0 @@ FetchBridge.prototype.getUserAgent = function () { |
@@ -1,1 +0,1 @@ | ||
export declare const IMPLEMENTATION_VERSION = "2.6.0"; | ||
export declare const IMPLEMENTATION_VERSION = "2.7.0"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.IMPLEMENTATION_VERSION = '2.6.0'; | ||
exports.IMPLEMENTATION_VERSION = '2.7.0'; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "conjure-client", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"description": "An HTTP bridge library for use in front end applications and generated conjure code", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -48,3 +48,3 @@ /** | ||
userAgent: IUserAgent | IUserAgent[] | Array<Supplier<IUserAgent>>; | ||
token?: string | Supplier<string>; | ||
token?: string | Supplier<string> | Supplier<Promise<string>>; | ||
fetch?: FetchFunction; | ||
@@ -62,3 +62,3 @@ } | ||
private readonly getBaseUrl: Supplier<string>; | ||
private readonly getToken: Supplier<string | undefined>; | ||
private readonly getToken: Supplier<string | Promise<string> | undefined>; | ||
private readonly fetch: FetchFunction | undefined; | ||
@@ -167,3 +167,3 @@ private readonly userAgentSuppliers: Array<Supplier<IUserAgent>>; | ||
private makeFetchCall(params: IHttpEndpointOptions): Promise<IFetchResponse> { | ||
private async makeFetchCall(params: IHttpEndpointOptions): Promise<IFetchResponse> { | ||
const query = this.buildQueryString(params.queryArguments); | ||
@@ -190,3 +190,3 @@ const url = `${this.getBaseUrl()}/${this.buildPath(params)}${query.length > 0 ? `?${query}` : ""}`; | ||
const token = this.getToken(); | ||
const token = await this.getToken(); | ||
if (token !== undefined) { | ||
@@ -193,0 +193,0 @@ fetchRequestInit.headers = { ...fetchRequestInit.headers, Authorization: `Bearer ${token}` }; |
@@ -1,1 +0,1 @@ | ||
export const IMPLEMENTATION_VERSION = '2.6.0'; | ||
export const IMPLEMENTATION_VERSION = '2.7.0'; |
Sorry, the diff of this file is not supported yet
88630
1698