c8osdkvuejs
Advanced tools
Comparing version 0.0.0-beta9 to 2.2.0
{ | ||
"name": "c8osdkvuejs", | ||
"version": "0.0.0-beta9", | ||
"version": "2.2.0", | ||
"description": "convertigo's MBaaS client API service", | ||
@@ -23,3 +23,2 @@ "main": "bundle/index.umd.js", | ||
}, | ||
"keywords": [ | ||
@@ -45,10 +44,8 @@ "MBaaS", | ||
"@types/node": "^8.5.2", | ||
"@types/pouchdb": "6.3.1", | ||
"c8osdkjscore": "0.0.0-beta12", | ||
"pouchdb-browser": "6.3.4", | ||
"rxjs": "5.5.2", | ||
"sw-toolbox": "3.6.0", | ||
"zone.js": "0.8.18", | ||
"vue-resource":"1.5.0", | ||
"axios":"0.18.0" | ||
"@types/pouchdb": "6.3.2", | ||
"pouchdb-browser": "6.4.3", | ||
"rxjs": "5.5.10", | ||
"zone.js": "0.8.26", | ||
"axios": "0.18.0", | ||
"c8osdkjscore": "1.0.0" | ||
}, | ||
@@ -82,10 +79,5 @@ "devDependencies": { | ||
"webpack": "3.10.0", | ||
"typescript": "2.4.2", | ||
"typescript": "2.6.2", | ||
"browserify": "16.2.0" | ||
}, | ||
"peerDependencies": { | ||
"rxjs": ">= 5.4.3 <= 5.5.2", | ||
"zone.js": ">= 0.8.17 <= 0.8.18", | ||
"sw-toolbox": "~3.6.0" | ||
} | ||
} |
@@ -1,6 +0,6 @@ | ||
[![Build Status](https://api.travis-ci.org/convertigo/c8osdk-angular.svg?branch=master)](https://travis-ci.org/convertigo/c8osdk-angular) [![npm version](https://img.shields.io/npm/v/c8osdkangular.svg)](https://www.npmjs.com/package/c8osdkangular) | ||
[![Build Status](https://travis-ci.org/convertigo/c8osdk-vuejs.svg?branch=master)](https://travis-ci.org/convertigo/c8osdk-vuejs) [![npm version](https://img.shields.io/npm/v/c8osdkvuejs.svg)](https://www.npmjs.com/package/c8osdkvuejs) | ||
# C8oSDKAngular # | ||
# C8oSDKVueJS # | ||
This is the Convertigo provider for Angular | ||
This is the Convertigo library for Vue.js | ||
@@ -12,9 +12,11 @@ Convertigo Client SDK is a set of libraries used by mobile or Windows desktop applications to access Convertigo Server services. An application using the SDK can easily access Convertigo services such as Sequences and Transactions. | ||
Client SDK is available for: | ||
* Android Native apps as a standard Gradle dependency | ||
* iOS native apps as a standard Cocoapod | ||
* [Android Native](https://github.com/convertigo/c8osdk-android) apps as a standard Gradle dependency | ||
* [iOS native](https://github.com/convertigo/c8osdk-ios) apps as a standard Cocoapod | ||
* Windows desktop or Xamarin apps as Nugets or Xamarin Components | ||
* Google Angular framework as an NPM package | ||
* [Google Angular framework](https://github.com/convertigo/c8osdk-angular) as an NPM package | ||
* [Vue.js](https://github.com/convertigo/c8osdk-vuejs) Framework as an NPM package | ||
This current package is the Angular SDK. For others SDKs see official Convertigo Documentation. | ||
This current package is the Vue.js SDK. For others SDKs see official Convertigo Documentation. | ||
## Documentation ## | ||
@@ -24,13 +26,6 @@ | ||
In Angular dependency injection is used to create a C8o instance | ||
import { C8o } from "c8osdkangular"; | ||
import { C8o } from "c8osdkvuejs" | ||
… | ||
// You must declare C8o within your NgModules C8o as a provider. | ||
// Then you will be able to get C8o object instancied thanks to Angular's dependency injection as the following example : | ||
export class MyClass { | ||
constructor(private c8o: C8o) { | ||
} | ||
} | ||
const c8o = new C8o() | ||
@@ -49,15 +44,18 @@ | ||
import { C8o, C8oSettings } from "c8osdkangular"; | ||
import { C8o, C8oSettings } from "c8osdkvuejs" | ||
… | ||
// The only way | ||
let settings: C8oSettings = new C8oSettings(); | ||
let settings: C8oSettings = new C8oSettings() | ||
settings | ||
.setEndPoint("https://demo.convertigo.net/cems/projects/sampleMobileCtfGallery") | ||
.setDefaultDatabaseName("mydb_fullsync") | ||
.setTimeout(30000); | ||
//Then we need to assign C8oSettings object to our C8o object | ||
c8o.init(settings); | ||
.setTimeout(30000) | ||
// Then we need to assign C8oSettings object to our C8o object | ||
c8o.init(settings) | ||
c8o.finalizeInit().then(() => { | ||
// do stuff with a complete instanciated object | ||
}) | ||
// all settings can be retrieve from a C8o or C8oSettings instance | ||
let timeout : number = c8o.timeout; | ||
let timeout : number = c8o.timeout | ||
@@ -79,13 +77,13 @@ #### Calling a Convertigo requestable with call parameters #### | ||
).then((response: any, parameters: Object) => { | ||
//handle repsonse | ||
// handle repsonse | ||
return null; | ||
}); | ||
}) | ||
// the verbose way | ||
let parameters : Object = new Object({"firstname" : "John", "lastname": "Doe"}); | ||
let parameters : Object = new Object({"firstname" : "John", "lastname": "Doe"}) | ||
c8o.callJsonObject("getSimpleData", parameters) | ||
.then((response: any, parameters: Object) => { | ||
//handle repsonse | ||
// handle repsonse | ||
return null; | ||
}); | ||
}) | ||
@@ -92,0 +90,0 @@ |
@@ -5,5 +5,4 @@ import { C8oCore, C8oSettings } from "c8osdkjscore"; | ||
readonly sdkVersion: string; | ||
newdef(): void; | ||
init(c8oSettings?: C8oSettings): Promise<any>; | ||
finalizeInit(): Promise<any>; | ||
} |
@@ -13,6 +13,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var index_1 = require("axios/index"); | ||
var c8osdkjscore_1 = require("c8osdkjscore"); | ||
var Observable_1 = require("rxjs/Observable"); | ||
var c8oHttpInterface_service_1 = require("./c8oHttpInterface.service"); | ||
var index_1 = require("axios/index"); | ||
var C8o = (function (_super) { | ||
@@ -25,5 +25,2 @@ __extends(C8o, _super); | ||
_this.c8oLogger = new c8osdkjscore_1.C8oLogger(_this, true); | ||
if (global["window"] === undefined) { | ||
global["window"] = {}; | ||
} | ||
return _this; | ||
@@ -38,16 +35,4 @@ } | ||
}); | ||
C8o.prototype.newdef = function () { | ||
console.log('jajjaj'); | ||
document.addEventListener("DOMContentLoaded", function () { | ||
if (window) { | ||
window.console.log("dans l'event"); | ||
window.alert("dans l'event"); | ||
} | ||
}); | ||
}; | ||
C8o.prototype.init = function (c8oSettings) { | ||
var _this = this; | ||
document.addEventListener("DOMContentLoaded", function () { | ||
return null; | ||
}); | ||
var nullableEndpoint = true; | ||
@@ -61,3 +46,3 @@ if (c8oSettings !== undefined) { | ||
this.promiseConstructor = new Promise(function (resolve) { | ||
if (window.location.href.startsWith("http") && window.location.href.indexOf("/DisplayObjects") != -1) { | ||
if (window.location.href.startsWith("http") && window.location.href.indexOf("/DisplayObjects") !== -1) { | ||
var n = window.location.href.indexOf("/DisplayObjects"); | ||
@@ -143,3 +128,3 @@ _this.endpoint = window.location.href.substring(0, n); | ||
} | ||
if (window["cblite"] != undefined) { | ||
if (window["cblite"] !== undefined) { | ||
window["cblite"].getURL(function (err, url) { | ||
@@ -146,0 +131,0 @@ if (err) { |
@@ -1,15 +0,6 @@ | ||
import {C8oCore, C8oLogger, C8oSettings, C8oException, C8oExceptionMessage, C8oFullSyncCbl, C8oFullSync} from "c8osdkjscore"; | ||
import axios, { AxiosAdapter, AxiosError, AxiosInstance, AxiosRequestConfig, | ||
AxiosResponse, Cancel, Canceler, CancelToken, CancelTokenSource} from "axios/index"; | ||
import {C8oCore, C8oException, C8oExceptionMessage, C8oFullSyncCbl, C8oLogger, C8oSettings} from "c8osdkjscore"; | ||
import {Observable} from "rxjs/Observable"; | ||
import {C8oHttpInterface} from "./c8oHttpInterface.service"; | ||
import axios, { | ||
AxiosRequestConfig, | ||
AxiosResponse, | ||
AxiosError, | ||
AxiosInstance, | ||
AxiosAdapter, | ||
Cancel, | ||
CancelToken, | ||
CancelTokenSource, | ||
Canceler | ||
} from "axios/index"; | ||
@@ -23,5 +14,2 @@ export class C8o extends C8oCore { | ||
this.c8oLogger = new C8oLogger(this, true); | ||
if (global["window"] === undefined) { | ||
global["window"] = {}; | ||
} | ||
} | ||
@@ -32,17 +20,3 @@ | ||
} | ||
public newdef(): void { | ||
console.log('jajjaj'); | ||
document.addEventListener("DOMContentLoaded", () => { | ||
if (window) { | ||
window.console.log("dans l'event"); | ||
window.alert("dans l'event"); | ||
} | ||
}); | ||
} | ||
public init(c8oSettings?: C8oSettings): Promise<any> { | ||
document.addEventListener("DOMContentLoaded", () => { | ||
return null; | ||
}); | ||
let nullableEndpoint = true; | ||
@@ -58,36 +32,33 @@ if (c8oSettings !== undefined) { | ||
// get the url from window.location | ||
if (window.location.href.startsWith("http") && window.location.href.indexOf("/DisplayObjects") != -1) { | ||
let n = window.location.href.indexOf("/DisplayObjects"); | ||
if (window.location.href.startsWith("http") && window.location.href.indexOf("/DisplayObjects") !== -1) { | ||
const n = window.location.href.indexOf("/DisplayObjects"); | ||
this.endpoint = window.location.href.substring(0, n); | ||
resolve(); | ||
} | ||
// else if project is running on device or serve by ionic serve | ||
// get the uri from env.json | ||
else { | ||
} else { | ||
let uri = ""; | ||
if (window.location.href.startsWith("file://")) { | ||
uri = (window.location.href.substring(0, window.location.href.indexOf("/index.html"))) + "/env.json" | ||
} | ||
else { | ||
uri = (window.location.href.substring(0, | ||
window.location.href.indexOf("/index.html"))) + "/env.json"; | ||
} else { | ||
uri = window.location.origin + "/env.json"; | ||
} | ||
this.httpPublic.get(uri) | ||
.then(data => { | ||
this.data = data; | ||
//noinspection TypeScriptUnresolvedVariable | ||
let remoteBase = data["remoteBase"].toString(); | ||
let n = remoteBase.indexOf("/_private"); | ||
this.endpoint = remoteBase.substring(0, n); | ||
this._automaticRemoveSplashsCreen = data["splashScreenRemoveMode"] !== "manual"; | ||
resolve(); | ||
}).catch(error => { | ||
alert("Missing env.json file"); | ||
let errMsg: string; | ||
if (error instanceof Error) { | ||
errMsg = error.message; | ||
} else { | ||
errMsg = `${error.status} - ${error.statusText || ""} ${error}`; | ||
} | ||
return Observable.throw(errMsg); | ||
}); | ||
.then((data) => { | ||
this.data = data; | ||
//noinspection TypeScriptUnresolvedVariable | ||
const remoteBase = data["remoteBase"].toString(); | ||
const n = remoteBase.indexOf("/_private"); | ||
this.endpoint = remoteBase.substring(0, n); | ||
this._automaticRemoveSplashsCreen = data["splashScreenRemoveMode"] !== "manual"; | ||
resolve(); | ||
}).catch((error) => { | ||
alert("Missing env.json file"); | ||
let errMsg: string; | ||
if (error instanceof Error) { | ||
errMsg = error.message; | ||
} else { | ||
errMsg = `${error.status} - ${error.statusText || ""} ${error}`; | ||
} | ||
return Observable.throw(errMsg); | ||
}); | ||
} | ||
@@ -141,4 +112,4 @@ }).then(() => { | ||
*/ | ||
public finalizeInit(): Promise<any>{ | ||
this.promiseFinInit = new Promise((resolve)=>{ | ||
public finalizeInit(): Promise<any> { | ||
this.promiseFinInit = new Promise((resolve) => { | ||
Promise.all([this.promiseInit]).then(() => { | ||
@@ -156,8 +127,7 @@ /** | ||
*/ | ||
if (window["cblite"] != undefined) { | ||
if (window["cblite"] !== undefined) { | ||
window["cblite"].getURL((err, url) => { | ||
if (err) { | ||
resolve(); | ||
} | ||
else{ | ||
} else { | ||
url = url.replace(new RegExp("/$"), ""); | ||
@@ -168,4 +138,3 @@ this.couchUrl = url; | ||
}); | ||
} | ||
else { | ||
} else { | ||
resolve(); | ||
@@ -177,2 +146,2 @@ } | ||
} | ||
} | ||
} |
@@ -1,17 +0,17 @@ | ||
import { C8o } from "./c8o.service"; | ||
import { C8oHttpInterfaceCore } from "c8osdkjscore/src/c8o/c8oHttpInterfaceCore"; | ||
import { C8oProgress } from "c8osdkjscore/src/c8o/c8oProgress"; | ||
import { C8oResponseListener } from "c8osdkjscore/src/c8o/c8oResponse"; | ||
import { C8oProgress } from "c8osdkjscore/src/c8o/c8oProgress"; | ||
import { C8o } from "./c8o.service"; | ||
export declare class C8oHttpInterface extends C8oHttpInterfaceCore { | ||
constructor(c8o: C8o); | ||
checkFile(parameters: Object): number; | ||
transformRequest(parameters: Object): string; | ||
transformRequestformdata(parameters: Object): FormData; | ||
transformRequestfileNative(parameters: Object): any; | ||
checkFile(parameters: any): number; | ||
transformRequest(parameters: any): string; | ||
transformRequestformdata(parameters: any): FormData; | ||
transformRequestfileNative(parameters: any): any; | ||
handleRequest(url: string, parameters: any, c8oResponseListener?: C8oResponseListener): Promise<any>; | ||
uploadFilePluginNative(url: string, parameters: any, c8oResponseListener: C8oResponseListener): Promise<any>; | ||
httpPost(url: string, parameters: any): Promise<any>; | ||
uploadFileHttp(url: string, form: FormData, parameters: any, c8oResponseListener: C8oResponseListener): Promise<any>; | ||
handleProgress(event: any, progress: C8oProgress, parameters: any, c8oResponseListener: C8oResponseListener, varNull: JSON): void; | ||
private isCordova(); | ||
handleRequest(url: string, parameters: Object, c8oResponseListener?: C8oResponseListener): Promise<any>; | ||
uploadFilePluginNative(url: string, parameters: Object, c8oResponseListener: C8oResponseListener): Promise<any>; | ||
httpPost(url: string, parameters: Object): Promise<any>; | ||
uploadFileHttp(url: string, form: FormData, parameters: Object, c8oResponseListener: C8oResponseListener): Promise<any>; | ||
handleProgress(event: any, progress: C8oProgress, parameters: any, c8oResponseListener: C8oResponseListener, varNull: JSON): void; | ||
} |
@@ -48,15 +48,11 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var c8o_service_1 = require("./c8o.service"); | ||
var c8oHttpInterfaceCore_1 = require("c8osdkjscore/src/c8o/c8oHttpInterfaceCore"); | ||
var c8oProgress_1 = require("c8osdkjscore/src/c8o/c8oProgress"); | ||
var c8oExceptionMessage_1 = require("c8osdkjscore/src/c8o/Exception/c8oExceptionMessage"); | ||
var c8oHttpRequestException_1 = require("c8osdkjscore/src/c8o/Exception/c8oHttpRequestException"); | ||
var c8oExceptionMessage_1 = require("c8osdkjscore/src/c8o/Exception/c8oExceptionMessage"); | ||
var c8o_service_1 = require("./c8o.service"); | ||
var C8oHttpInterface = (function (_super) { | ||
__extends(C8oHttpInterface, _super); | ||
function C8oHttpInterface(c8o) { | ||
var _this = _super.call(this, c8o) || this; | ||
if (global["window"] === undefined) { | ||
global["window"] = {}; | ||
} | ||
return _this; | ||
return _super.call(this, c8o) || this; | ||
} | ||
@@ -95,3 +91,5 @@ C8oHttpInterface.prototype.checkFile = function (parameters) { | ||
for (var p1 in parameters[p]) { | ||
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(parameters[p][p1])); | ||
if (parameters[p].hasOwnProperty(p1)) { | ||
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(parameters[p][p1])); | ||
} | ||
} | ||
@@ -112,3 +110,4 @@ } | ||
if (parameters[p][p1] instanceof FileList) { | ||
for (var i = 0; i < parameters[p][p1].length; i++) { | ||
for (var _i = 0, _a = parameters[p][p1]; _i < _a.length; _i++) { | ||
var i = _a[_i]; | ||
formdata.append(p, parameters[p][p1][i], parameters[p][p1][i].name); | ||
@@ -124,3 +123,4 @@ } | ||
if (parameters[p] instanceof FileList) { | ||
for (var j = 0; j < parameters[p].length; j++) { | ||
for (var _b = 0, _c = parameters[p]; _b < _c.length; _b++) { | ||
var j = _c[_b]; | ||
formdata.append(p, parameters[p][j], parameters[p][j].name); | ||
@@ -161,13 +161,2 @@ } | ||
}; | ||
C8oHttpInterface.prototype.isCordova = function () { | ||
if (this._isCordova == null) { | ||
if (window["cordova"] != undefined) { | ||
this._isCordova = true; | ||
} | ||
else { | ||
this._isCordova = false; | ||
} | ||
} | ||
return this._isCordova; | ||
}; | ||
C8oHttpInterface.prototype.handleRequest = function (url, parameters, c8oResponseListener) { | ||
@@ -207,5 +196,5 @@ return __awaiter(this, void 0, void 0, function () { | ||
options.fileKey = files[0][0]; | ||
options.fileName = files[0][1].substr(files[0][1].lastIndexOf('/') + 1); | ||
options.fileName = files[0][1].substr(files[0][1].lastIndexOf("/") + 1); | ||
options.params = data[1]; | ||
var headersObject = { 'Accept': 'application/json', 'x-convertigo-sdk': this.c8o.sdkVersion }; | ||
var headersObject = { "Accept": "application/json", "x-convertigo-sdk": this.c8o.sdkVersion }; | ||
Object.assign(headersObject, this.c8o.headers); | ||
@@ -232,3 +221,4 @@ options.headers = headersObject; | ||
parameters = this.transformRequest(parameters); | ||
var headersObject = { "Content-Type": "application/x-www-form-urlencoded", "x-convertigo-sdk": this.c8o.sdkVersion }; | ||
var headersObject = { "Content-Type": "application/x-www-form-urlencoded", | ||
"x-convertigo-sdk": this.c8o.sdkVersion }; | ||
Object.assign(headersObject, this.c8o.headers); | ||
@@ -241,7 +231,7 @@ var headers = { headers: (headersObject) }; | ||
headers: headers, | ||
withCredentials: true | ||
withCredentials: true, | ||
}).then(function (response) { | ||
return resolve(response.data); | ||
}).catch(function (error) { | ||
resolve({ "error": (new c8oHttpRequestException_1.C8oHttpRequestException(c8oExceptionMessage_1.C8oExceptionMessage.runHttpRequest(), error)) | ||
resolve({ error: (new c8oHttpRequestException_1.C8oHttpRequestException(c8oExceptionMessage_1.C8oExceptionMessage.runHttpRequest(), error)), | ||
}); | ||
@@ -257,7 +247,7 @@ }); | ||
headers: headers, | ||
withCredentials: true | ||
withCredentials: true, | ||
}).then(function (response) { | ||
return resolve(response.data); | ||
}).catch(function (error) { | ||
resolve({ "error": (new c8oHttpRequestException_1.C8oHttpRequestException(c8oExceptionMessage_1.C8oExceptionMessage.runHttpRequest(), error)) | ||
resolve({ error: (new c8oHttpRequestException_1.C8oHttpRequestException(c8oExceptionMessage_1.C8oExceptionMessage.runHttpRequest(), error)), | ||
}); | ||
@@ -273,3 +263,3 @@ }); | ||
var _this = this; | ||
var headersObject = { 'Accept': 'application/json', 'x-convertigo-sdk': this.c8o.sdkVersion }; | ||
var headersObject = { "Accept": "application/json", "x-convertigo-sdk": this.c8o.sdkVersion }; | ||
Object.assign(headersObject, this.c8o.headers); | ||
@@ -287,7 +277,7 @@ var headers = { headers: headersObject }; | ||
headers: headers, | ||
withCredentials: true | ||
withCredentials: true, | ||
}).then(function (response) { | ||
return resolve(response.data); | ||
}).catch(function (error) { | ||
resolve({ "error": (new c8oHttpRequestException_1.C8oHttpRequestException(c8oExceptionMessage_1.C8oExceptionMessage.runHttpRequest(), error)) | ||
resolve({ error: (new c8oHttpRequestException_1.C8oHttpRequestException(c8oExceptionMessage_1.C8oExceptionMessage.runHttpRequest(), error)), | ||
}); | ||
@@ -299,3 +289,3 @@ }); | ||
else { | ||
return new Promise(function (resolve, reject) { | ||
return new Promise(function (resolve) { | ||
Promise.all([_this.p1]).then(function () { | ||
@@ -306,7 +296,7 @@ _this.c8o.httpPublic.post({ url: url, data: form, withCredentials: true, headers: headers, onUploadProgress: function (event) { | ||
headers: headers, | ||
withCredentials: true | ||
withCredentials: true, | ||
}).then(function (response) { | ||
return resolve(response.data); | ||
}).catch(function (error) { | ||
resolve({ "error": (new c8oHttpRequestException_1.C8oHttpRequestException(c8oExceptionMessage_1.C8oExceptionMessage.runHttpRequest(), error)) | ||
resolve({ error: (new c8oHttpRequestException_1.C8oHttpRequestException(c8oExceptionMessage_1.C8oExceptionMessage.runHttpRequest(), error)), | ||
}); | ||
@@ -321,11 +311,12 @@ }); | ||
progress.total = event.total; | ||
if (event.loaded != event.total) { | ||
progress.finished = false; | ||
} | ||
else { | ||
progress.finished = true; | ||
} | ||
progress.finished = event.loaded === event.total; | ||
parameters[c8o_service_1.C8o.ENGINE_PARAMETER_PROGRESS] = progress; | ||
c8oResponseListener.onJsonResponse(varNull, parameters); | ||
}; | ||
C8oHttpInterface.prototype.isCordova = function () { | ||
if (this._isCordova == null) { | ||
this._isCordova = window["cordova"] !== undefined; | ||
} | ||
return this._isCordova; | ||
}; | ||
return C8oHttpInterface; | ||
@@ -332,0 +323,0 @@ }(c8oHttpInterfaceCore_1.C8oHttpInterfaceCore)); |
@@ -1,7 +0,7 @@ | ||
import {C8o} from "./c8o.service"; | ||
import {C8oHttpInterfaceCore} from "c8osdkjscore/src/c8o/c8oHttpInterfaceCore"; | ||
import {C8oProgress} from "c8osdkjscore/src/c8o/c8oProgress"; | ||
import {C8oResponseJsonListener, C8oResponseListener} from "c8osdkjscore/src/c8o/c8oResponse"; | ||
import {C8oProgress} from "c8osdkjscore/src/c8o/c8oProgress"; | ||
import {C8oExceptionMessage} from "c8osdkjscore/src/c8o/Exception/c8oExceptionMessage"; | ||
import {C8oHttpRequestException} from "c8osdkjscore/src/c8o/Exception/c8oHttpRequestException"; | ||
import {C8oExceptionMessage} from "c8osdkjscore/src/c8o/Exception/c8oExceptionMessage"; | ||
import {C8o} from "./c8o.service"; | ||
@@ -11,5 +11,2 @@ export class C8oHttpInterface extends C8oHttpInterfaceCore { | ||
super(c8o); | ||
if (global["window"] === undefined) { | ||
global["window"] = {}; | ||
} | ||
} | ||
@@ -25,12 +22,11 @@ | ||
*/ | ||
checkFile(parameters: Object): number{ | ||
for (let p in parameters) { | ||
public checkFile(parameters: any): number { | ||
for (const p in parameters) { | ||
if (parameters[p] instanceof Array) { | ||
for (let p1 in parameters[p]) { | ||
for (const p1 in parameters[p]) { | ||
//noinspection JSUnfilteredForInLoop | ||
if(parameters[p][p1] instanceof FileList){ | ||
if (parameters[p][p1] instanceof FileList) { | ||
return 1; | ||
} | ||
else if(this.isCordova()){ | ||
if(parameters[p][p1] instanceof URL){ | ||
} else if (this.isCordova()) { | ||
if (parameters[p][p1] instanceof URL) { | ||
return 2; | ||
@@ -40,9 +36,7 @@ } | ||
} | ||
} | ||
else { | ||
if(parameters[p] instanceof FileList){ | ||
} else { | ||
if (parameters[p] instanceof FileList) { | ||
return 1; | ||
} | ||
else if(this.isCordova()){ | ||
if(parameters[p]instanceof URL){ | ||
} else if (this.isCordova()) { | ||
if (parameters[p] instanceof URL) { | ||
return 2; | ||
@@ -61,16 +55,17 @@ } | ||
*/ | ||
transformRequest(parameters: Object): string { | ||
let str = []; | ||
for (let p in parameters) { | ||
public transformRequest(parameters: any): string { | ||
const str = []; | ||
for (const p in parameters) { | ||
if (parameters[p] instanceof Array) { | ||
for (let p1 in parameters[p]) { | ||
//noinspection JSUnfilteredForInLoop | ||
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(parameters[p][p1])); | ||
for (const p1 in parameters[p]) { | ||
if (parameters[p].hasOwnProperty(p1)) { | ||
//noinspection JSUnfilteredForInLoop | ||
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(parameters[p][p1])); | ||
} | ||
} | ||
} | ||
else { | ||
} else { | ||
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(parameters[p])); | ||
} | ||
} | ||
let query = str.join("&"); | ||
const query = str.join("&"); | ||
// Add this to instruct Convertigo server to remove any name space in the jSON keys | ||
@@ -86,24 +81,21 @@ // to prevent keys like this: 'namespace:key' | ||
*/ | ||
transformRequestformdata(parameters: Object): FormData { | ||
let formdata : FormData= new FormData(); | ||
for (let p in parameters) { | ||
public transformRequestformdata(parameters: any): FormData { | ||
const formdata: FormData = new FormData(); | ||
for (const p in parameters) { | ||
if (parameters[p] instanceof Array) { | ||
for (let p1 in parameters[p]) { | ||
if(parameters[p][p1] instanceof FileList){ | ||
for (var i = 0; i < parameters[p][p1].length; i++) { | ||
for (const p1 in parameters[p]) { | ||
if (parameters[p][p1] instanceof FileList) { | ||
for (const i of parameters[p][p1]) { | ||
formdata.append(p, parameters[p][p1][i], parameters[p][p1][i].name); | ||
} | ||
} else { | ||
formdata.append(p, parameters[p][p1]); | ||
} | ||
else{ | ||
formdata.append(p, parameters[p][p1]) | ||
} | ||
} | ||
} | ||
else { | ||
if(parameters[p] instanceof FileList) { | ||
for (var j = 0; j < parameters[p].length; j++) { | ||
} else { | ||
if (parameters[p] instanceof FileList) { | ||
for (const j of parameters[p]) { | ||
formdata.append(p, parameters[p][j], parameters[p][j].name); | ||
} | ||
} | ||
else{ | ||
} else { | ||
formdata.append(p, parameters[p]); | ||
@@ -116,4 +108,2 @@ } | ||
/** | ||
@@ -124,21 +114,18 @@ * Extract file from parameters and return and array containing a file and params | ||
*/ | ||
transformRequestfileNative(parameters: Object): any{ | ||
let file: Array<any> = new Array(); | ||
let params: Object = new Object(); | ||
for (let p in parameters) { | ||
public transformRequestfileNative(parameters: any): any { | ||
const file: any[] = new Array(); | ||
const params: any = new Object(); | ||
for (const p in parameters) { | ||
if (parameters[p] instanceof Array) { | ||
for (let p1 in parameters[p]) { | ||
if(parameters[p][p1] instanceof URL){ | ||
for (const p1 in parameters[p]) { | ||
if (parameters[p][p1] instanceof URL) { | ||
file.push([p1, parameters[p][p1]]); | ||
} | ||
else{ | ||
} else { | ||
params[p1] = parameters[p][p1]["href"]; | ||
} | ||
} | ||
} | ||
else { | ||
if(parameters[p] instanceof URL) { | ||
} else { | ||
if (parameters[p] instanceof URL) { | ||
file.push([p, parameters[p]["href"]]); | ||
} | ||
else{ | ||
} else { | ||
params[p] = parameters[p]; | ||
@@ -152,20 +139,2 @@ } | ||
/** | ||
* Check if we are in cordova environment | ||
* @return {boolean} | ||
*/ | ||
private isCordova():boolean{ | ||
if(this._isCordova == null){ | ||
if(window["cordova"]!= undefined){ | ||
this._isCordova = true; | ||
} | ||
else{ | ||
this._isCordova = false; | ||
} | ||
} | ||
return this._isCordova; | ||
} | ||
/** | ||
* Handle the request | ||
@@ -177,3 +146,3 @@ * @param {string} url | ||
*/ | ||
async handleRequest(url: string, parameters: Object, c8oResponseListener?: C8oResponseListener): Promise<any> { | ||
public async handleRequest(url: string, parameters: any, c8oResponseListener?: C8oResponseListener): Promise<any> { | ||
if (parameters["__sequence"] !== undefined) { | ||
@@ -184,3 +153,3 @@ if (parameters["__sequence"].indexOf("#") !== -1) { | ||
} | ||
switch (this.checkFile(parameters)){ | ||
switch (this.checkFile(parameters)) { | ||
case 0: { | ||
@@ -190,4 +159,4 @@ return this.httpPost(url, parameters); | ||
case 1: { | ||
let form = this.transformRequestformdata(parameters); | ||
return this.uploadFileHttp(url,form,parameters,c8oResponseListener); | ||
const form = this.transformRequestformdata(parameters); | ||
return this.uploadFileHttp(url, form, parameters, c8oResponseListener); | ||
} | ||
@@ -201,3 +170,2 @@ case 2: { | ||
/** | ||
@@ -210,18 +178,19 @@ * Upload file with native plugin | ||
*/ | ||
uploadFilePluginNative(url: string, parameters: Object, c8oResponseListener: C8oResponseListener):Promise<any>{ | ||
let progress: C8oProgress = new C8oProgress(); | ||
public uploadFilePluginNative(url: string, parameters: any, | ||
c8oResponseListener: C8oResponseListener): Promise<any> { | ||
const progress: C8oProgress = new C8oProgress(); | ||
progress.pull = false; | ||
let varNull: JSON = null; | ||
let data = this.transformRequestfileNative(parameters); | ||
let files = data[0]; | ||
let options = new window["FileUploadOptions"](); | ||
const varNull: JSON = null; | ||
const data = this.transformRequestfileNative(parameters); | ||
const files = data[0]; | ||
const options = new window["FileUploadOptions"](); | ||
options.fileKey = files[0][0]; | ||
options.fileName = files[0][1].substr(files[0][1].lastIndexOf('/') + 1); | ||
options.fileName = files[0][1].substr(files[0][1].lastIndexOf("/") + 1); | ||
options.params = data[1]; | ||
let headersObject = {'Accept':'application/json', 'x-convertigo-sdk': this.c8o.sdkVersion}; | ||
const headersObject = {"Accept": "application/json", "x-convertigo-sdk": this.c8o.sdkVersion}; | ||
Object.assign(headersObject, this.c8o.headers); | ||
options.headers = headersObject; | ||
return new Promise((resolve,reject)=>{ | ||
return new Promise((resolve, reject) => { | ||
Promise.all([this.p1]).then(() => { | ||
var ft = new window["FileTransfer"](); | ||
const ft = new window["FileTransfer"](); | ||
ft.onprogress = (progressEvent) => { | ||
@@ -232,3 +201,3 @@ if (progressEvent.lengthComputable) { | ||
}; | ||
ft.upload(files[0][1], encodeURI(url), ((resp => { | ||
ft.upload(files[0][1], encodeURI(url), (((resp) => { | ||
resolve(resp); | ||
@@ -248,7 +217,8 @@ })), ((err) => { | ||
*/ | ||
httpPost(url: string, parameters: Object): Promise<any>{ | ||
public httpPost(url: string, parameters: any): Promise<any> { | ||
parameters = this.transformRequest(parameters); | ||
let headersObject = {"Content-Type": "application/x-www-form-urlencoded", "x-convertigo-sdk": this.c8o.sdkVersion}; | ||
const headersObject = {"Content-Type": "application/x-www-form-urlencoded", | ||
"x-convertigo-sdk": this.c8o.sdkVersion}; | ||
Object.assign(headersObject, this.c8o.headers); | ||
let headers = {headers: (headersObject)}; | ||
const headers = {headers: (headersObject)}; | ||
if (this.firstCall) { | ||
@@ -258,8 +228,8 @@ this.p1 = new Promise((resolve, reject) => { | ||
this.c8o.httpPublic.post(url, parameters, { | ||
headers: headers, | ||
withCredentials: true | ||
}).then(response => | ||
resolve(response.data) | ||
).catch(error => { | ||
resolve({"error" : (new C8oHttpRequestException(C8oExceptionMessage.runHttpRequest(), error)) | ||
headers, | ||
withCredentials: true, | ||
}).then((response) => | ||
resolve(response.data), | ||
).catch((error) => { | ||
resolve({error : (new C8oHttpRequestException(C8oExceptionMessage.runHttpRequest(), error)), | ||
}); | ||
@@ -269,13 +239,12 @@ }); | ||
return this.p1; | ||
} | ||
else { | ||
} else { | ||
return new Promise((resolve, reject) => { | ||
Promise.all([this.p1]).then(() => { | ||
this.c8o.httpPublic.post(url, parameters, { | ||
headers: headers, | ||
withCredentials: true | ||
}).then(response => | ||
resolve(response.data) | ||
).catch(error => { | ||
resolve({"error" : (new C8oHttpRequestException(C8oExceptionMessage.runHttpRequest(), error)) | ||
headers, | ||
withCredentials: true, | ||
}).then((response) => | ||
resolve(response.data), | ||
).catch((error) => { | ||
resolve({error : (new C8oHttpRequestException(C8oExceptionMessage.runHttpRequest(), error)), | ||
}); | ||
@@ -299,11 +268,11 @@ }); | ||
*/ | ||
uploadFileHttp(url: string, form: FormData, parameters: Object, c8oResponseListener: C8oResponseListener): Promise<any>{ | ||
let headersObject = {'Accept':'application/json', 'x-convertigo-sdk': this.c8o.sdkVersion}; | ||
public uploadFileHttp(url: string, form: FormData, parameters: any, | ||
c8oResponseListener: C8oResponseListener): Promise<any> { | ||
const headersObject = {"Accept": "application/json", "x-convertigo-sdk": this.c8o.sdkVersion}; | ||
Object.assign(headersObject, this.c8o.headers); | ||
let headers = {headers: headersObject}; | ||
let progress: C8oProgress = new C8oProgress(); | ||
const headers = {headers: headersObject}; | ||
const progress: C8oProgress = new C8oProgress(); | ||
progress.pull = false; | ||
let varNull: JSON = null; | ||
const varNull: JSON = null; | ||
if (this.firstCall) { | ||
@@ -313,11 +282,11 @@ this.p1 = new Promise((resolve) => { | ||
this.c8o.httpPublic.post({url: url, data: form, withCredentials: true, headers: headers, onUploadProgress: function (event) { | ||
this.c8o.httpPublic.post({url, data: form, withCredentials: true, headers, onUploadProgress(event) { | ||
this.handleProgress(event, progress, parameters, c8oResponseListener, varNull); | ||
}}, { | ||
headers: headers, | ||
withCredentials: true | ||
}).then(response => | ||
resolve(response.data) | ||
).catch(error => { | ||
resolve({"error" : (new C8oHttpRequestException(C8oExceptionMessage.runHttpRequest(), error)) | ||
headers, | ||
withCredentials: true, | ||
}).then((response) => | ||
resolve(response.data), | ||
).catch((error) => { | ||
resolve({error : (new C8oHttpRequestException(C8oExceptionMessage.runHttpRequest(), error)), | ||
}); | ||
@@ -327,15 +296,14 @@ }); | ||
return this.p1; | ||
} | ||
else { | ||
return new Promise((resolve, reject) => { | ||
} else { | ||
return new Promise((resolve) => { | ||
Promise.all([this.p1]).then(() => { | ||
this.c8o.httpPublic.post({url: url, data: form, withCredentials: true, headers: headers, onUploadProgress: function (event) { | ||
this.c8o.httpPublic.post({url, data: form, withCredentials: true, headers, onUploadProgress(event) { | ||
this.handleProgress(event, progress, parameters, c8oResponseListener, varNull); | ||
}}, { | ||
headers: headers, | ||
withCredentials: true | ||
}).then(response => | ||
resolve(response.data) | ||
).catch(error => { | ||
resolve({"error" : (new C8oHttpRequestException(C8oExceptionMessage.runHttpRequest(), error)) | ||
headers, | ||
withCredentials: true, | ||
}).then((response) => | ||
resolve(response.data), | ||
).catch((error) => { | ||
resolve({error : (new C8oHttpRequestException(C8oExceptionMessage.runHttpRequest(), error)), | ||
}); | ||
@@ -348,3 +316,2 @@ }); | ||
/** | ||
@@ -358,11 +325,7 @@ * Handle progress | ||
*/ | ||
handleProgress(event: any, progress: C8oProgress, parameters: any, c8oResponseListener: C8oResponseListener, varNull: JSON): void{ | ||
public handleProgress(event: any, progress: C8oProgress, parameters: any, | ||
c8oResponseListener: C8oResponseListener, varNull: JSON): void { | ||
progress.current = event.loaded; | ||
progress.total = event.total; | ||
if(event.loaded != event.total){ | ||
progress.finished = false; | ||
} | ||
else{ | ||
progress.finished = true; | ||
} | ||
progress.finished = event.loaded === event.total; | ||
parameters[C8o.ENGINE_PARAMETER_PROGRESS] = progress; | ||
@@ -372,2 +335,13 @@ (c8oResponseListener as C8oResponseJsonListener).onJsonResponse(varNull, parameters); | ||
} | ||
} | ||
/** | ||
* Check if we are in cordova environment | ||
* @return {boolean} | ||
*/ | ||
private isCordova(): boolean { | ||
if (this._isCordova == null) { | ||
this._isCordova = window["cordova"] !== undefined; | ||
} | ||
return this._isCordova; | ||
} | ||
} |
import { C8oUtilsCore } from "c8osdkjscore"; | ||
export declare class C8oUtils extends C8oUtilsCore { | ||
private http; | ||
constructor(); | ||
} |
@@ -13,2 +13,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var index_1 = require("axios/index"); | ||
var c8osdkjscore_1 = require("c8osdkjscore"); | ||
@@ -18,3 +19,5 @@ var C8oUtils = (function (_super) { | ||
function C8oUtils() { | ||
return _super.call(this) || this; | ||
var _this = _super.call(this) || this; | ||
_this.http = index_1.default; | ||
return _this; | ||
} | ||
@@ -21,0 +24,0 @@ return C8oUtils; |
@@ -0,9 +1,13 @@ | ||
import axios, { AxiosAdapter, AxiosError, AxiosInstance, AxiosRequestConfig, | ||
AxiosResponse, Cancel, Canceler, CancelToken, CancelTokenSource} from "axios/index"; | ||
import {C8oUtilsCore} from "c8osdkjscore"; | ||
export class C8oUtils extends C8oUtilsCore{ | ||
export class C8oUtils extends C8oUtilsCore { | ||
private http: any; | ||
public constructor() { | ||
super(); | ||
this.http = axios; | ||
} | ||
} | ||
} |
@@ -1,44 +0,3 @@ | ||
import {C8oSettings} from "c8osdkjscore/src/c8o/c8oSettings"; | ||
export * from "./c8o/c8o.service"; | ||
export * from "./c8o/c8oUtils.service"; | ||
export * from "c8osdkjscore"; | ||
// export * from "../node_modules/c8osdkjscore/src/c8o/c8oSettings"; | ||
/*export * from "./c8o/c8oBase"; | ||
export * from "./c8o/c8oCallTask"; | ||
export * from "./c8o/fullsyncpolicy"; | ||
export * from "./c8o/c8oFullSyncChangeListener"; | ||
export * from "./c8o/c8oFullSyncCbl"; | ||
export * from "./c8o/fullsyncpostdocumentparameter"; | ||
export * from "./c8o/c8oFullSync"; | ||
export * from "./c8o/c8oFullSyncTranslator"; | ||
export * from "./c8o/c8oHttpInterface"; | ||
export * from "./c8o/c8oLocalCache"; | ||
export * from "./c8o/c8oLocalCacheResponse"; | ||
export * from "./c8o/c8oLogger"; | ||
export * from "./c8o/c8oLogLevel"; | ||
export * from "./c8o/c8oProgress"; | ||
export * from "./c8o/c8oPromise"; | ||
export * from "./c8o/c8oResponse"; | ||
export * from "./c8o/c8oSettings"; | ||
export * from "./c8o/c8oTranslator"; | ||
export * from "./c8o/c8oUtilsCore"; | ||
export * from "./c8o/fullSyncAttachmentParameter"; | ||
export * from "./c8o/fullSyncDatabase"; | ||
export * from "./c8o/fullSyncDeleteDocumentParameter"; | ||
export * from "./c8o/fullSyncGetDocumentParameter"; | ||
export * from "./c8o/fullSyncGetViewParameter"; | ||
export * from "./c8o/fullSyncreplication"; | ||
export * from "./c8o/fullSyncRequestable"; | ||
export * from "./c8o/fullSyncResponse"; | ||
export * from "./c8o/priority.service"; | ||
export * from "./c8o/Exception/c8oCouchBaseLiteException"; | ||
export * from "./c8o/Exception/c8oException"; | ||
export * from "./c8o/Exception/c8oExceptionListener"; | ||
export * from "./c8o/Exception/c8oExceptionMessage"; | ||
export * from "./c8o/Exception/c8oHttpRequestException"; | ||
export * from "./c8o/Exception/c8oRessourceNotFoundException"; | ||
export * from "./c8o/Exception/c8oUnavailableLocalCacheException";*/ | ||
@@ -7,2 +7,3 @@ { | ||
"experimentalDecorators": true, | ||
"target": "es5", | ||
@@ -9,0 +10,0 @@ "lib": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
7
1
75547
1002
1
90
+ Addedc8osdkjscore@1.0.0(transitive)
+ Addedrxjs@5.5.10(transitive)
+ Addedsymbol-observable@1.0.1(transitive)
- Removedsw-toolbox@3.6.0
- Removedvue-resource@1.5.0
- Removed@sindresorhus/is@0.7.0(transitive)
- Removed@types/pouchdb@6.3.1(transitive)
- Removedc8osdkjscore@0.0.0-beta12(transitive)
- Removedcacheable-request@2.1.4(transitive)
- Removedclone-response@1.0.2(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddebug@2.6.4(transitive)
- Removeddecode-uri-component@0.2.2(transitive)
- Removeddecompress-response@3.3.0(transitive)
- Removedduplexer3@0.1.5(transitive)
- Removedfrom2@2.3.0(transitive)
- Removedget-stream@3.0.0(transitive)
- Removedgot@8.3.2(transitive)
- Removedhas-symbol-support-x@1.4.2(transitive)
- Removedhas-to-string-tag-x@1.4.1(transitive)
- Removedhttp-cache-semantics@3.8.1(transitive)
- Removedinto-stream@3.1.0(transitive)
- Removedis-object@1.0.2(transitive)
- Removedis-plain-obj@1.1.0(transitive)
- Removedis-retry-allowed@1.2.0(transitive)
- Removedisarray@0.0.11.0.0(transitive)
- Removedisurl@1.0.0(transitive)
- Removedjson-buffer@3.0.0(transitive)
- Removedkeyv@3.0.0(transitive)
- Removedlowercase-keys@1.0.01.0.1(transitive)
- Removedmimic-response@1.0.1(transitive)
- Removedms@0.7.3(transitive)
- Removednormalize-url@2.0.1(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedp-cancelable@0.4.1(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-is-promise@1.1.0(transitive)
- Removedp-timeout@2.0.1(transitive)
- Removedpath-to-regexp@1.9.0(transitive)
- Removedpify@3.0.0(transitive)
- Removedpouchdb-browser@6.3.4(transitive)
- Removedprepend-http@2.0.0(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedquery-string@5.1.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedresponselike@1.0.2(transitive)
- Removedrxjs@5.5.2(transitive)
- Removedsafe-buffer@5.1.25.2.1(transitive)
- Removedserviceworker-cache-polyfill@4.0.0(transitive)
- Removedsort-keys@2.0.0(transitive)
- Removedstrict-uri-encode@1.1.0(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedsw-toolbox@3.6.0(transitive)
- Removedsymbol-observable@1.2.0(transitive)
- Removedtimed-out@4.0.1(transitive)
- Removedurl-parse-lax@3.0.0(transitive)
- Removedurl-to-options@1.0.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedvue-resource@1.5.0(transitive)
- Removedzone.js@0.8.18(transitive)
Updated@types/pouchdb@6.3.2
Updatedc8osdkjscore@1.0.0
Updatedpouchdb-browser@6.4.3
Updatedrxjs@5.5.10
Updatedzone.js@0.8.26