carbone-sdk-js
Advanced tools
Comparing version 1.1.7 to 1.2.0
@@ -1,2 +0,2 @@ | ||
var d=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var T=a=>d(a,"__esModule",{value:!0});var S=(a,r)=>{for(var e in r)d(a,e,{get:r[e],enumerable:!0})},D=(a,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of v(r))!y.call(a,n)&&(e||n!=="default")&&d(a,n,{get:()=>r[n],enumerable:!(t=m(r,n))||t.enumerable});return a};var A=(a=>(r,e)=>a&&a.get(r)||(e=D(T({}),r,1),a&&a.set(r,e),e))(typeof WeakMap!="undefined"?new WeakMap:0);var R={};S(R,{default:()=>K});var f=function(a){let r={apiUrl:"https://render.carbone.io",accessToken:a,apiVersion:3};return{getAccessToken:function(){return r.accessToken},setAccessToken:function(e){r.accessToken=e},getApiVersion:function(){return r.apiVersion},setApiVersion:function(e){r.apiVersion=e},getApiUrl:function(){return r.apiUrl},setApiUrl:function(e){r.apiUrl=e},addTemplate:async function(e,t=""){var n=new FormData;if(!e)throw new Error("Carbone SDK addTemplate error: the file argument is not valid.");return n.append("payload",t),n.append("template",e),await(await fetch(`${r.apiUrl}/template`,{method:"post",body:n,headers:{"carbone-version":r.apiVersion,Authorization:"Bearer "+r.accessToken}})).json()},deleteTemplate:async function(e){if(!e)throw new Error("Carbone SDK deleteTemplate error: the templateId argument is not valid.");return await(await fetch(`${r.apiUrl}/template/${e}`,{method:"delete",headers:{"carbone-version":r.apiVersion,Authorization:"Bearer "+r.accessToken}})).json()},getTemplate:async function(e,t="blob"){if(!e)throw new Error("Carbone SDK getTemplate error: the templateId argument is not valid.");if(["blob","text"].indexOf(t)===-1)throw new Error("Carbone SDK getTemplate error: the responseType argument is not valid.");return await(await fetch(`${r.apiUrl}/template/${e}`,{method:"get",headers:{"carbone-version":r.apiVersion,Authorization:"Bearer "+r.accessToken}}))[t]()},renderReport:async function(e,t){if(!e)throw new Error("Carbone SDK renderReport error: the templateId argument is not valid.");if(!t)throw new Error("Carbone SDK renderReport error: the data argument is not valid.");return await(await fetch(`${r.apiUrl}/render/${e}`,{method:"post",body:JSON.stringify(t),headers:{"Content-type":"application/json","carbone-version":r.apiVersion,Authorization:"Bearer "+r.accessToken}})).json()},getReport:async function(e,t="blob"){if(!e)throw new Error("Carbone SDK getReport error: the renderId argument is not valid.");if(["blob","text"].indexOf(t)===-1)throw new Error("Carbone SDK getReport error: the responseType argument is not valid.");let n=await fetch(`${r.apiUrl}/render/${e}`,{method:"get",headers:{"carbone-version":r.apiVersion,Authorization:"Bearer "+r.accessToken}});return{content:await n[t](),name:this.getReportNameFromHeader(n.headers)}},render:async function(e,t,n="",i="blob"){if(!e)throw new Error("Carbone SDK render error: the templateId argument is not valid.");if(!t)throw new Error("Carbone SDK render error: the data argument is not valid.");let o=null;if(typeof e=="string"&&e.length===64&&Object.prototype.hasOwnProperty.call(e,"name")===!1&&(o=await this.renderReport(e,t)),o===null||o.success===!1){let p=await(typeof e=="string"?e:await e.arrayBuffer().then(s=>new Uint8Array(s))),c=await this.generateTemplateId(p,n);if(c&&(o=await this.renderReport(c,t)),o===null||o.success===!1){let s=await this.addTemplate(e,n);s&&s.success===!0&&s.data.templateId&&(o=await this.renderReport(s.data.templateId,t))}}if(!o||o.success===!1||!o.data.renderId)throw new Error("Carbone SDK render error: the rendering has failled.");return this.getReport(o.data.renderId,i)},generateTemplateId:async function(e,t=""){function n(c){for(var s="",l=new DataView(c),u=0;u<l.byteLength;u+=4){var w=l.getUint32(u),g=w.toString(16),h="00000000",b=(h+g).slice(-h.length);s+=b}return s}var i=typeof e=="string"?new TextEncoder("utf-8").encode(e):e,o=typeof t=="string"?new TextEncoder("utf-8").encode(t):t,p=new Uint8Array(o.length+i.length);return p.set(o),p.set(i,o.length),await crypto.subtle.digest("SHA-256",p).then(function(c){return n(c)})},getReportNameFromHeader(e){if(!e)return null;let t=e.get("content-disposition");if(!t)return null;let n=t.split("=");if(n.length===1||!n[1])return null;let i=n[1];return i[0]==='"'&&i[i.length-1]==='"'&&(i=i.substr(1,n[1].length-2)),i}}};window.carboneRenderSDK=f;window.carboneSDK=f;var K=f;module.exports=A(R); | ||
var f=Object.defineProperty,K=Object.defineProperties,R=Object.getOwnPropertyDescriptor,A=Object.getOwnPropertyDescriptors,E=Object.getOwnPropertyNames,b=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var m=(o,r,a)=>r in o?f(o,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):o[r]=a,p=(o,r)=>{for(var a in r||(r={}))y.call(r,a)&&m(o,a,r[a]);if(b)for(var a of b(r))C.call(r,a)&&m(o,a,r[a]);return o},v=(o,r)=>K(o,A(r));var H=(o,r)=>{for(var a in r)f(o,a,{get:r[a],enumerable:!0})},U=(o,r,a,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of E(r))!y.call(o,t)&&t!==a&&f(o,t,{get:()=>r[t],enumerable:!(e=R(r,t))||e.enumerable});return o};var x=o=>U(f({},"__esModule",{value:!0}),o);var j={};H(j,{default:()=>V});module.exports=x(j);var w=function(o){let r={apiUrl:"https://api.carbone.io",accessToken:o,apiVersion:4,apiHeaders:{}},a=function(e,t,n){return fetch(`${r.apiUrl}${t}`,v(p({method:e},n!=null&&n.body?{body:n.body}:{}),{headers:p(p({"carbone-version":r.apiVersion,Authorization:"Bearer "+r.accessToken},n!=null&&n.headers?n.headers:{}),r!=null&&r.apiHeaders?r.apiHeaders:{})}))};return{setApiHeaders:function(e){e&&typeof e=="object"&&(r.apiHeaders=e)},getApiHeaders:function(){return r.apiHeaders},getAccessToken:function(){return r.accessToken},setAccessToken:function(e){r.accessToken=e},getApiVersion:function(){return r.apiVersion},setApiVersion:function(e){r.apiVersion=e},getApiUrl:function(){return r.apiUrl},setApiUrl:function(e){r.apiUrl=e},addTemplate:async function(e,t=""){var n=new FormData;if(!e)throw new Error("Carbone SDK addTemplate error: the file argument is not valid.");return n.append("payload",t),n.append("template",e),await(await a("post","/template",{body:n})).json()},deleteTemplate:async function(e){if(!e)throw new Error("Carbone SDK deleteTemplate error: the templateId argument is not valid.");return await(await a("delete",`/template/${e}`)).json()},getTemplate:async function(e,t="blob"){if(!e)throw new Error("Carbone SDK getTemplate error: the templateId argument is not valid.");if(["blob","text"].indexOf(t)===-1)throw new Error("Carbone SDK getTemplate error: the responseType argument is not valid.");return await(await a("get",`/template/${e}`))[t]()},renderReport:async function(e,t){if(!e)throw new Error("Carbone SDK renderReport error: the templateId argument is not valid.");if(!t)throw new Error("Carbone SDK renderReport error: the data argument is not valid.");return await(await a("post",`/render/${e}`,{body:JSON.stringify(t),headers:{"Content-type":"application/json"}})).json()},getReport:async function(e,t="blob"){if(!e)throw new Error("Carbone SDK getReport error: the renderId argument is not valid.");if(["blob","text"].indexOf(t)===-1)throw new Error("Carbone SDK getReport error: the responseType argument is not valid.");let n=await a("get",`/render/${e}`);return{content:await n[t](),name:this.getReportNameFromHeader(n.headers)}},render:async function(e,t,n="",i="blob"){if(!e)throw new Error("Carbone SDK render error: the templateId argument is not valid.");if(!t)throw new Error("Carbone SDK render error: the data argument is not valid.");let s=null;if(typeof e=="string"&&e.length===64&&Object.prototype.hasOwnProperty.call(e,"name")===!1&&(s=await this.renderReport(e,t)),s===null||s.success===!1){let d=await(typeof e=="string"?e:await e.arrayBuffer().then(c=>new Uint8Array(c))),u=await this.generateTemplateId(d,n);if(u&&(s=await this.renderReport(u,t)),s===null||s.success===!1){let c=await this.addTemplate(e,n);c&&c.success===!0&&c.data.templateId&&(s=await this.renderReport(c.data.templateId,t))}}if(!s||s.success===!1||!s.data.renderId)throw new Error("Carbone SDK render error: the rendering has failled.");return this.getReport(s.data.renderId,i)},generateTemplateId:async function(e,t=""){function n(u){for(var c="",h=new DataView(u),l=0;l<h.byteLength;l+=4){var T=h.getUint32(l),S=T.toString(16),g="00000000",D=(g+S).slice(-g.length);c+=D}return c}var i=typeof e=="string"?new TextEncoder("utf-8").encode(e):e,s=typeof t=="string"?new TextEncoder("utf-8").encode(t):t,d=new Uint8Array(s.length+i.length);return d.set(s),d.set(i,s.length),await crypto.subtle.digest("SHA-256",d).then(function(u){return n(u)})},getReportNameFromHeader(e){if(!e)return null;let t=e.get("content-disposition");if(!t)return null;let n=t.split("=");if(n.length===1||!n[1])return null;let i=n[1];return i[0]==='"'&&i[i.length-1]==='"'&&(i=i.substr(1,n[1].length-2)),i}}};window.carboneRenderSDK=w;window.carboneSDK=w;var V=w; | ||
//# sourceMappingURL=main.js.map |
{ | ||
"name": "carbone-sdk-js", | ||
"version": "1.1.7", | ||
"version": "1.2.0", | ||
"description": "The javascript SDK to use Carbone Render easily ", | ||
@@ -25,3 +25,3 @@ "homepage": "https://github.com/carboneio/carbone-sdk-js", | ||
"core-js": "=3.20.0", | ||
"esbuild": "=0.14.6", | ||
"esbuild": "=0.17.18", | ||
"eslint": "=8.5.0", | ||
@@ -28,0 +28,0 @@ "eslint-config-prettier": "=8.3.0", |
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
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
58430
36
2