servicestack-client
Advanced tools
Comparing version 0.0.37 to 0.0.38
{ | ||
"name": "servicestack-client", | ||
"title": "ServiceStack JavaScript Utils", | ||
"version": "0.0.37", | ||
"version": "0.0.38", | ||
"description": "ServiceStack's TypeScript library providing convenience utilities in developing web apps. Integrates with ServiceStack's Server features including ServiceClient, Server Events, Error Handling and Validation", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/ServiceStack/servicestack-client", |
@@ -161,3 +161,3 @@ import 'fetch-everywhere'; | ||
getSubscriptionId(): string; | ||
updateSubscriber(request: UpdateEventSubscriber): Promise<any>; | ||
updateSubscriber(request: UpdateEventSubscriber): Promise<void>; | ||
subscribeToChannels(...channels: string[]): Promise<void>; | ||
@@ -164,0 +164,0 @@ unsubscribeFromChannels(...channels: string[]): Promise<void>; |
106
src/index.js
@@ -398,3 +398,2 @@ "use strict"; | ||
_this.update(request.subscribeChannels, request.unsubscribeChannels); | ||
return null; | ||
}).catch(this.onError); | ||
@@ -436,3 +435,6 @@ }; | ||
.then(function (r) { return r.map(function (x) { return _this.toServerEventUser(x); }); }) | ||
.catch(this.onError); | ||
.catch(function (e) { | ||
_this.onError(e); | ||
return []; | ||
}); | ||
}; | ||
@@ -456,5 +458,5 @@ ServerEventsClient.prototype.toServerEventUser = function (map) { | ||
}; | ||
ServerEventsClient.UnknownChannel = "*"; | ||
return ServerEventsClient; | ||
}()); | ||
ServerEventsClient.UnknownChannel = "*"; | ||
exports.ServerEventsClient = ServerEventsClient; | ||
@@ -499,14 +501,14 @@ var ServerEventReceiver = (function () { | ||
} | ||
HttpMethods.Get = "GET"; | ||
HttpMethods.Post = "POST"; | ||
HttpMethods.Put = "PUT"; | ||
HttpMethods.Delete = "DELETE"; | ||
HttpMethods.Patch = "PATCH"; | ||
HttpMethods.Head = "HEAD"; | ||
HttpMethods.Options = "OPTIONS"; | ||
HttpMethods.hasRequestBody = function (method) { | ||
return !(method === "GET" || method === "DELETE" || method === "HEAD" || method === "OPTIONS"); | ||
}; | ||
return HttpMethods; | ||
}()); | ||
HttpMethods.Get = "GET"; | ||
HttpMethods.Post = "POST"; | ||
HttpMethods.Put = "PUT"; | ||
HttpMethods.Delete = "DELETE"; | ||
HttpMethods.Patch = "PATCH"; | ||
HttpMethods.Head = "HEAD"; | ||
HttpMethods.Options = "OPTIONS"; | ||
HttpMethods.hasRequestBody = function (method) { | ||
return !(method === "GET" || method === "DELETE" || method === "HEAD" || method === "OPTIONS"); | ||
}; | ||
exports.HttpMethods = HttpMethods; | ||
@@ -564,2 +566,5 @@ var GetAccessToken = (function () { | ||
}; | ||
JsonServiceClient.prototype.postBody = function (request, body) { | ||
return this.sendBody(HttpMethods.Post, request, body); | ||
}; | ||
JsonServiceClient.prototype.put = function (request, args) { | ||
@@ -571,2 +576,5 @@ return this.send(HttpMethods.Put, request, args); | ||
}; | ||
JsonServiceClient.prototype.putBody = function (request, body) { | ||
return this.sendBody(HttpMethods.Post, request, body); | ||
}; | ||
JsonServiceClient.prototype.patch = function (request, args) { | ||
@@ -578,2 +586,5 @@ return this.send(HttpMethods.Patch, request, args); | ||
}; | ||
JsonServiceClient.prototype.patchBody = function (request, body) { | ||
return this.sendBody(HttpMethods.Post, request, body); | ||
}; | ||
JsonServiceClient.prototype.createUrlFromDto = function (method, request) { | ||
@@ -592,4 +603,5 @@ var url = exports.combinePaths(this.replyBaseUrl, exports.nameOf(request)); | ||
}; | ||
JsonServiceClient.prototype.createRequest = function (method, request, args, url) { | ||
JsonServiceClient.prototype.createRequest = function (_a) { | ||
var _this = this; | ||
var method = _a.method, request = _a.request, args = _a.args, url = _a.url, body = _a.body; | ||
if (!url) | ||
@@ -630,3 +642,3 @@ url = this.createUrlFromDto(method, request); | ||
if (HttpMethods.hasRequestBody(method)) | ||
req.body = JSON.stringify(request); | ||
req.body = body || JSON.stringify(request); | ||
var opt = { url: url }; | ||
@@ -706,9 +718,23 @@ if (this.requestFilter != null) | ||
JsonServiceClient.prototype.send = function (method, request, args, url) { | ||
return this.sendRequest({ method: method, request: request, args: args, url: url }); | ||
}; | ||
JsonServiceClient.prototype.sendBody = function (method, request, body) { | ||
var url = exports.combinePaths(this.replyBaseUrl, exports.nameOf(request)); | ||
return this.sendRequest({ | ||
method: method, | ||
request: body, | ||
body: typeof body == "string" ? body : JSON.stringify(body), | ||
url: exports.appendQueryString(url, request), | ||
returns: request | ||
}); | ||
}; | ||
JsonServiceClient.prototype.sendRequest = function (info) { | ||
var _this = this; | ||
var _a = this.createRequest(info), req = _a[0], opt = _a[1]; | ||
var returns = info.returns || info.request; | ||
var holdRes = null; | ||
var _a = this.createRequest(method, request, args, url), req = _a[0], opt = _a[1]; | ||
return fetch(opt.url || req.url, req) | ||
.then(function (res) { | ||
holdRes = res; | ||
var response = _this.createResponse(res, request); | ||
var response = _this.createResponse(res, returns); | ||
return response; | ||
@@ -725,5 +751,5 @@ }) | ||
_this.bearerToken = r.accessToken; | ||
var _a = _this.createRequest(method, request, args), req = _a[0], opt = _a[1]; | ||
var _a = _this.createRequest(info), req = _a[0], opt = _a[1]; | ||
return fetch(opt.url || req.url, req) | ||
.then(function (res) { return _this.createResponse(res, request); }) | ||
.then(function (res) { return _this.createResponse(res, returns); }) | ||
.catch(function (res) { return _this.handleError(holdRes, res); }); | ||
@@ -735,5 +761,5 @@ }) | ||
return _this.onAuthenticationRequired().then(function () { | ||
var _a = _this.createRequest(method, request, args), req = _a[0], opt = _a[1]; | ||
var _a = _this.createRequest(info), req = _a[0], opt = _a[1]; | ||
return fetch(opt.url || req.url, req) | ||
.then(function (res) { return _this.createResponse(res, request); }) | ||
.then(function (res) { return _this.createResponse(res, returns); }) | ||
.catch(function (res) { return _this.handleError(holdRes, res); }); | ||
@@ -998,2 +1024,40 @@ }); | ||
}; | ||
exports.normalizeKey = function (key) { return key.toLowerCase().replace(/_/g, ''); }; | ||
var isArray = function (o) { return Object.prototype.toString.call(o) === '[object Array]'; }; | ||
exports.normalize = function (dto, deep) { | ||
if (isArray(dto)) { | ||
if (!deep) | ||
return dto; | ||
var to = []; | ||
for (var i = 0; i < dto.length; i++) { | ||
to[i] = exports.normalize(dto[i], deep); | ||
} | ||
return to; | ||
} | ||
if (typeof dto != "object") | ||
return dto; | ||
var o = {}; | ||
for (var k in dto) { | ||
o[exports.normalizeKey(k)] = deep ? exports.normalize(dto[k], deep) : dto[k]; | ||
} | ||
return o; | ||
}; | ||
exports.getField = function (o, name) { | ||
return o == null || name == null ? null : | ||
o[name] || | ||
o[Object.keys(o).filter(function (k) { return exports.normalizeKey(k) === exports.normalizeKey(name); })[0] || '']; | ||
}; | ||
exports.parseResponseStatus = function (json, defaultMsg) { | ||
if (defaultMsg === void 0) { defaultMsg = null; } | ||
try { | ||
var err = JSON.parse(json); | ||
return exports.sanitize(err.ResponseStatus || err.responseStatus); | ||
} | ||
catch (e) { | ||
return { | ||
message: defaultMsg || e.message || e, | ||
__error: { error: e, json: json } | ||
}; | ||
} | ||
}; | ||
exports.toDate = function (s) { return new Date(parseFloat(/Date\(([^)]+)\)/.exec(s)[1])); }; | ||
@@ -1000,0 +1064,0 @@ exports.toDateFmt = function (s) { return exports.dateFmt(exports.toDate(s)); }; |
@@ -521,3 +521,3 @@ import 'fetch-everywhere'; | ||
updateSubscriber(request:UpdateEventSubscriber) { | ||
updateSubscriber(request:UpdateEventSubscriber): Promise<void> { | ||
if (request.id == null) | ||
@@ -529,7 +529,6 @@ request.id = this.getSubscriptionId(); | ||
this.update(request.subscribeChannels, request.unsubscribeChannels); | ||
return null; | ||
}).catch(this.onError); | ||
} | ||
subscribeToChannels(...channels:string[]) { | ||
subscribeToChannels(...channels:string[]): Promise<void> { | ||
let request = new UpdateEventSubscriber(); | ||
@@ -545,3 +544,3 @@ request.id = this.getSubscriptionId(); | ||
unsubscribeFromChannels(...channels:string[]) { | ||
unsubscribeFromChannels(...channels:string[]): Promise<void> { | ||
let request = new UpdateEventSubscriber(); | ||
@@ -548,0 +547,0 @@ request.id = this.getSubscriptionId(); |
Sorry, the diff of this file is not supported yet
157142
2472