@sneko/ionic-appauth
Version:
Intergration for OpenId/AppAuth-JS into Ionic V3/4/5
74 lines (73 loc) • 3.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CordovaRequestor = void 0;
var tslib_1 = require("tslib");
var cordova_document_1 = require("./cordova-document");
var appauth_1 = require("@openid/appauth");
var http_1 = require("@ionic-native/http");
// REQUIRES CORDOVA PLUGINS
// cordova-plugin-advanced-http
var CordovaRequestor = /** @class */ (function (_super) {
tslib_1.__extends(CordovaRequestor, _super);
function CordovaRequestor() {
var _this = this;
cordova_document_1.CordovaDocument.ready(function () { return http_1.HTTP.setDataSerializer('utf8'); });
_this = _super.call(this) || this;
return _this;
}
CordovaRequestor.prototype.xhr = function (settings) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!settings.method)
settings.method = "GET";
return [4 /*yield*/, cordova_document_1.CordovaDocument.ready()];
case 1:
_a.sent();
switch (settings.method) {
case "GET":
return [2 /*return*/, this.get(settings.url, settings.headers)];
case "POST":
return [2 /*return*/, this.post(settings.url, settings.data, settings.headers)];
case "PUT":
return [2 /*return*/, this.put(settings.url, settings.data, settings.headers)];
case "DELETE":
return [2 /*return*/, this.delete(settings.url, settings.headers)];
}
return [2 /*return*/];
}
});
});
};
CordovaRequestor.prototype.get = function (url, headers) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, http_1.HTTP.get(url, undefined, headers).then(function (response) { return JSON.parse(response.data); })];
});
});
};
CordovaRequestor.prototype.post = function (url, data, headers) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, http_1.HTTP.post(url, data, headers).then(function (response) { return JSON.parse(response.data); })];
});
});
};
CordovaRequestor.prototype.put = function (url, data, headers) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, http_1.HTTP.put(url, data, headers).then(function (response) { return JSON.parse(response.data); })];
});
});
};
CordovaRequestor.prototype.delete = function (url, headers) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, http_1.HTTP.delete(url, undefined, headers).then(function (response) { return JSON.parse(response.data); })];
});
});
};
return CordovaRequestor;
}(appauth_1.Requestor));
exports.CordovaRequestor = CordovaRequestor;