nd-common
Version:
3 lines (2 loc) • 8.56 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common/http"),require("rxjs"),require("rxjs/operators"),require("nd-common"),require("@angular/common"),require("@angular/http")):"function"==typeof define&&define.amd?define("nd-common/api",["exports","@angular/core","@angular/common/http","rxjs","rxjs/operators","nd-common","@angular/common","@angular/http"],t):t((e["nd-common"]=e["nd-common"]||{},e["nd-common"].api={}),e.ng.core,e.ng.common.http,e.rxjs,e.Rx.Observable.prototype,e["nd-common"],e.ng.common,e.ng.http)}(this,function(e,r,s,a,d,u,t,n){"use strict";var o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};var i=new r.InjectionToken("ndTokenController"),p=function(){function e(e,t){this.http=e,this.DEFAULT_REST_VERSION=u.APIVersions.two,this.tokenService=t}return e.prototype.call=function(r,t){var n=this;if(void 0===t&&(t=!0),r.url=this.getUrl(r.path,r.apiVersion),null==r.method&&(r.method=u.HttpMethod.Get),r.method==u.HttpMethod.Get&&r.queryArgs){var e=this.generateQueryArgs(r.queryArgs),o="?";-1<r.url.indexOf(o)&&(o="&"),r.url+=""+o+e}var i={};return i={headers:this.BaseHeaders,responseType:"json",observe:"response",body:r.body},this.http.request(r.method,r.url,i).pipe(d.catchError(function(e,t){return 401==e.status?n.tokenService.renew().pipe(d.mergeMap(function(e){return n.AccessToken=e,r.init.headers=n.BaseHeaders,i.headers=n.BaseHeaders,n.http.request(r.method,r.url,i)})):304==e.status?a.of(new s.HttpResponse({status:e.status})):a.throwError(e)}),d.map(function(e){return t?e.body:e}))},e.prototype.generateQueryArgs=function(n){var o="";return Object.keys(n).forEach(function(e){var t="";o.length&&(t="&");var r=n[e];Array.isArray(r)&&(r="object"==typeof r[0]?r.map(function(e){return e.ToString()}).join(","):r.join(",")),o+=t+e+"="+r}),o},Object.defineProperty(e.prototype,"AccessToken",{get:function(){return this.tokenService.token},set:function(e){this.tokenService.token=e.trim()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"BaseUrl",{get:function(){return this._baseUrl||(this._baseUrl=e.GenerateBaseUrl(this.tokenService.host,this.tokenService.useHttps)),this._baseUrl},enumerable:!0,configurable:!0}),e.GenerateBaseUrl=function(e,t,r){return void 0===e&&(e=u.NetDocumentsService.vault),void 0===t&&(t=!0),void 0===r&&(r=!0),(t?"https":"http")+"://"+(r?"api.":"")+e},e.prototype.getUrl=function(e,t){var r=this.BaseUrl;return r+=t||this.DEFAULT_REST_VERSION,r+=e},Object.defineProperty(e.prototype,"BaseHeaders",{get:function(){return new s.HttpHeaders({Authorization:"Bearer "+this.AccessToken,Accept:"application/json"})},enumerable:!0,configurable:!0}),e.urlEncodeString=function(e){return null!=e&&(u.CommonService.stringContainsAny(e,this.ENCODING_SUBSTRINGS)&&(e=encodeURIComponent(e)),e=encodeURIComponent(e)),e},e.attributeQueryEncode=function(e){return e&&0<e.length&&((-1<e.indexOf(",")||-1<e.indexOf('"'))&&((e=e.replace(/"/g,'""')).startsWith('"',0)||(e='"'+e),e.endsWith('"',e.length)||(e+='"')),e=encodeURIComponent(e)),e},e.cleanEnv=function(e){return e?("NB"!=getItemType(e)||/\/NB\d/.test(e)||(e.indexOf("|")<0&&(e+="|0"),e=encodeURI(e.split("|")[0])+"|"+e.split("|")[1]),e=e.replace(/\//g,":")):e},e.createFilterList=function(e){var t=" extension eq ";return(t+e.join(t)).trim()},e}();p.ENCODING_SUBSTRINGS=["/","&","\\","+","?","%"],p.decorators=[{type:r.Injectable}],p.ctorParameters=function(){return[{type:s.HttpClient},{type:undefined,decorators:[{type:r.Inject,args:[i]}]}]};var c=function(n){function e(e,t){var r=n.call(this,e,t)||this;return r.h=e,r.controllerUrl="/document",r}return function(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}(e,n),e.prototype.getInfo=function(e){if(e.id==undefined)return a.throwError("id is required.");var t=new u.CallParameters;return t.apiVersion=u.APIVersions.two,t.method=u.HttpMethod.Get,t.path=this.controllerUrl+"/"+e.id+"/info",e.queryArgs!==undefined&&(t.queryArgs=e.queryArgs),this.call(t)},e.prototype.getListOfDocuments=function(e){if(e.id==undefined)return a.throwError("id is required.");var t=new u.CallParameters;return t.apiVersion=u.APIVersions.two,t.method=u.HttpMethod.Post,t.path=this.controllerUrl+"/list",t.body="id="+e.id+"&select="+e.queryArgs.select,t.headers=this.BaseHeaders,t.headers.append("Content-Type","application/x-www-form-urlencoded"),this.call(t)},e.prototype.getRecent=function(e,t,r){void 0===r&&(r="");var n=new u.CallParameters;return null!==t&&t!==undefined||(t=u.RecentDocumentType.All),e.queryArgs!==undefined&&(n.queryArgs=e.queryArgs),n.headers=n.headers?n.headers:this.BaseHeaders,r?n.headers.append("If-Modified-Since",r):(n.headers.append("Cache-Control","no-cache"),n.headers.append("Pragma","no-cache"),n.headers.append("Expires","Sat, 01 Jan 2000 00:00:00 GMT")),n.path=this.controllerUrl+"/recent/"+u.RecentDocumentType[t].toLowerCase(),n.method=u.HttpMethod.Get,n.apiVersion=u.APIVersions.two,this.call(n,!1)},e.prototype.getGrantAccessRequestInfo=function(e){var t=new u.CallParameters;if(e.Id==undefined)throw"id is required.";return t.path=this.controllerUrl+"/"+e.Id+"/grant_access_request_info",t.method=u.HttpMethod.Get,t.apiVersion=u.APIVersions.two,this.call(t)},e.prototype.getLinkedDocuments=function(e){if(e.id==undefined)return a.throwError("Document getLinkedDocuments id is required.");var t=new u.CallParameters;return t.apiVersion=u.APIVersions.two,t.method=u.HttpMethod.Get,t.path=this.controllerUrl+"/"+e.id+"/linked",e.queryArgs!==undefined&&(t.queryArgs=e.queryArgs),this.call(t)},e.prototype.putNewVersion=function(e){if(e.id==undefined)return a.Observable["throw"]("Document putNewVersion id is required.");var t=new u.CallParameters;return t.apiVersion=u.APIVersions.one,t.method=u.HttpMethod.Put,t.path=this.controllerUrl+"/"+e.id+"/new",null!=e.body&&(t.path+="?",e.body.Name!=undefined&&(t.path+="vername="+e.body.Name+"&"),e.body.Description!=undefined&&(t.path+="version_description="+e.body.Description+"&"),e.body.Official&&(t.path+="official=Y")),this.call(t)},e.prototype.checkIn=function(e){if(e.id==undefined)return a.Observable["throw"]("Document checkIn id is required.");var t="checkin",r=new u.CallParameters;if(r.apiVersion=u.APIVersions.one,r.method=u.HttpMethod.Post,r.path=""+this.controllerUrl,r.headers=this.BaseHeaders,e.file!=undefined){var n=new FormData;n.append("action",t),n.append("id",e.id),e.notify!==undefined&&n.append("notify",e.notify),e.extension!==undefined&&n.append("extension",e.extension),n.append("file",e.file),r.body=n}else r.headers.append("Content-Type","application/x-www-form-urlencoded"),r.body="id="+e.id+"&action="+t,e.notify!==undefined&&(r.body+="¬ify="+e.notify);return this.call(r)},e.prototype.putNewVersionContents=function(e){if(e.id==undefined)return a.Observable["throw"]("Document putFileContents id is required.");if(e.file==undefined)return a.Observable["throw"]("Document putFileContents file is required.");if(e.extension==undefined)return a.Observable["throw"]("Document putFileContents extension is required.");var t=new u.CallParameters;t.apiVersion=u.APIVersions.one,t.method=u.HttpMethod.Put,t.path=this.controllerUrl+"/"+e.id+"/new?",e.extension!=undefined&&(t.path+="extension="+e.extension),e.verName!=undefined&&(t.path+="&vername="+e.verName),t.headers=this.BaseHeaders;var r=new FormData;return r.append("file",e.file),r.append("processData","false"),r.append("contentType",e.file.type),t.body=r,this.call(t)},e.prototype.getHistory=function(e){if(e.id==undefined)return a.throwError("Document getLinkedDocuments id is required.");var t=new u.CallParameters;return t.apiVersion=u.APIVersions.one,t.method=u.HttpMethod.Get,t.path=this.controllerUrl+"/"+e.id+"/history",e.queryArgs!==undefined&&(t.queryArgs=e.queryArgs),this.call(t)},e}(p);c.decorators=[{type:r.Injectable}],c.ctorParameters=function(){return[{type:s.HttpClient},{type:undefined,decorators:[{type:r.Inject,args:[i]}]}]};var l=function(){function t(){}return t.forRoot=function(e){return{ngModule:t,providers:[{provide:i,useExisting:r.forwardRef(function(){return e})},c]}},t}();l.decorators=[{type:r.NgModule,args:[{imports:[t.CommonModule,n.HttpModule]}]}],e.ndApiModule=l,e.DocumentControllerService=c,e.ND_TOKEN_CONTROLLER=i,e.ɵa=p,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=nd-common-api.umd.min.js.map