@thisisagile/easy
Advanced tools
Comparing version 1.8.7 to 1.8.8
import { ContentType } from './ContentType'; | ||
export declare class RequestOptions { | ||
headers: { | ||
import { Enum, JsonValue } from '../types'; | ||
export declare class RequestOptions extends Enum { | ||
readonly type: ContentType; | ||
readonly headers: { | ||
[key: string]: any; | ||
}; | ||
constructor(contentType?: ContentType); | ||
static get json(): RequestOptions; | ||
static get text(): RequestOptions; | ||
static get xml(): RequestOptions; | ||
static get form(): RequestOptions; | ||
get contentType(): ContentType; | ||
set contentType(type: ContentType); | ||
type(type: ContentType): RequestOptions; | ||
authorization(auth: string): RequestOptions; | ||
accept(type: ContentType): RequestOptions; | ||
static Json: RequestOptions; | ||
static Text: RequestOptions; | ||
static Xml: RequestOptions; | ||
static Form: RequestOptions; | ||
constructor(type?: ContentType, headers?: { | ||
[key: string]: any; | ||
}); | ||
authorization: (auth: string) => this; | ||
accept: (type: ContentType) => this; | ||
bearer: (jwt: JsonValue) => this; | ||
} |
@@ -5,40 +5,31 @@ "use strict"; | ||
const ContentType_1 = require("./ContentType"); | ||
class RequestOptions { | ||
constructor(contentType = ContentType_1.ContentType.Json) { | ||
this.headers = {}; | ||
this.contentType = contentType; | ||
const types_1 = require("../types"); | ||
class RequestOptions extends types_1.Enum { | ||
constructor(type = ContentType_1.ContentType.Json, headers = {}) { | ||
super(type.name); | ||
this.type = type; | ||
this.headers = headers; | ||
this.authorization = (auth) => { | ||
this.headers.Authorization = auth; | ||
return this; | ||
}; | ||
this.accept = (type) => { | ||
this.headers.Accept = type.id; | ||
return this; | ||
}; | ||
this.bearer = (jwt) => { | ||
if (types_1.isNotEmpty(jwt)) { | ||
this.authorization(`Bearer ${jwt}`); | ||
} | ||
return this; | ||
}; | ||
this.headers['Content-Type'] = type.id; | ||
// this.headers['X-Correlation-Id'] = context.request.correlation ?? newId(); | ||
} | ||
static get json() { | ||
return new RequestOptions(); | ||
} | ||
static get text() { | ||
return new RequestOptions(ContentType_1.ContentType.Text); | ||
} | ||
static get xml() { | ||
return new RequestOptions(ContentType_1.ContentType.Xml); | ||
} | ||
static get form() { | ||
return new RequestOptions(ContentType_1.ContentType.Form); | ||
} | ||
get contentType() { | ||
return ContentType_1.ContentType.byId(this.headers['Content-Type']); | ||
} | ||
set contentType(type) { | ||
this.headers['Content-Type'] = type.id; | ||
} | ||
type(type) { | ||
this.contentType = type; | ||
return this; | ||
} | ||
authorization(auth) { | ||
this.headers.Authorization = auth; | ||
return this; | ||
} | ||
accept(type) { | ||
this.headers['Accept'] = type.id; | ||
return this; | ||
} | ||
} | ||
exports.RequestOptions = RequestOptions; | ||
RequestOptions.Json = new RequestOptions(ContentType_1.ContentType.Json); | ||
RequestOptions.Text = new RequestOptions(ContentType_1.ContentType.Text); | ||
RequestOptions.Xml = new RequestOptions(ContentType_1.ContentType.Xml); | ||
RequestOptions.Form = new RequestOptions(ContentType_1.ContentType.Form); | ||
//# sourceMappingURL=RequestOptions.js.map |
{ | ||
"name": "@thisisagile/easy", | ||
"version": "1.8.7", | ||
"version": "1.8.8", | ||
"description": "Straightforward library for building domain-driven microservice architectures", | ||
@@ -5,0 +5,0 @@ "author": "Sander Hoogendoorn", |
import { ContentType } from './ContentType'; | ||
import { Enum, isNotEmpty, JsonValue } from '../types'; | ||
export class RequestOptions { | ||
headers: { [key: string]: any } = {}; | ||
constructor(contentType: ContentType = ContentType.Json) { | ||
this.contentType = contentType; | ||
// this.headers['X-Correlation-Id'] = context.request.correlation ?? newId(); | ||
} | ||
export class RequestOptions extends Enum { | ||
static get json(): RequestOptions { | ||
return new RequestOptions(); | ||
} | ||
static Json = new RequestOptions(ContentType.Json); | ||
static Text = new RequestOptions(ContentType.Text); | ||
static Xml = new RequestOptions(ContentType.Xml); | ||
static Form = new RequestOptions(ContentType.Form); | ||
static get text(): RequestOptions { | ||
return new RequestOptions(ContentType.Text); | ||
} | ||
static get xml(): RequestOptions { | ||
return new RequestOptions(ContentType.Xml); | ||
} | ||
static get form(): RequestOptions { | ||
return new RequestOptions(ContentType.Form); | ||
} | ||
get contentType(): ContentType { | ||
return ContentType.byId(this.headers['Content-Type']); | ||
} | ||
set contentType(type: ContentType) { | ||
constructor(readonly type: ContentType = ContentType.Json, readonly headers: { [key: string]: any } = {}) { | ||
super(type.name); | ||
this.headers['Content-Type'] = type.id; | ||
// this.headers['X-Correlation-Id'] = context.request.correlation ?? newId(); | ||
} | ||
type(type: ContentType): RequestOptions { | ||
this.contentType = type; | ||
authorization = (auth: string): this => { | ||
this.headers.Authorization = auth; | ||
return this; | ||
} | ||
}; | ||
authorization(auth: string): RequestOptions { | ||
this.headers.Authorization = auth; | ||
accept = (type: ContentType): this => { | ||
this.headers.Accept = type.id; | ||
return this; | ||
} | ||
}; | ||
accept(type: ContentType): RequestOptions { | ||
this.headers['Accept'] = type.id; | ||
bearer = (jwt: JsonValue): this => { | ||
if (isNotEmpty(jwt)) { this.authorization(`Bearer ${jwt}`); } | ||
return this; | ||
} | ||
// | ||
// bearer(jwt: Jwt): RequestOptions { | ||
// return Try.ofDefined(() => jwt) | ||
// .map(j => this.authorization(`Bearer ${j.value}`)) | ||
// .recover(() => this).value; | ||
// } | ||
}; | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
107775
1620