linkedin-post-share
Advanced tools
Comparing version 1.1.12 to 1.1.13
@@ -1,1 +0,1 @@ | ||
var s=(p,t,e)=>new Promise((o,r)=>{var i=a=>{try{c(e.next(a))}catch(n){r(n)}},h=a=>{try{c(e.throw(a))}catch(n){r(n)}},c=a=>a.done?o(a.value):Promise.resolve(a.value).then(i,h);c((e=e.apply(p,t)).next())});import l,{AxiosError as u}from"axios";var d=class{constructor(t){this.accessToken=t;this.LINKEDIN_BASE_URL="https://api.linkedin.com";this.LINKEDIN_VERSION="202303"}getProfileData(){return s(this,null,function*(){var t;try{return(yield l(`${this.LINKEDIN_BASE_URL}/v2/me`,{method:"GET",headers:{Authorization:`Bearer ${this.accessToken}`}})).data}catch(e){return e instanceof u?(console.error("Cannot get profile data. Error: ",(t=e.response)==null?void 0:t.data),null):(console.error("Something went wrong. Error: ",e),null)}})}getPersonURN(){return s(this,null,function*(){let t=yield this.getProfileData();return!t||!t.id?null:`urn:li:person:${t.id}`})}createImageUploadRequest(t){return s(this,null,function*(){var e;try{return(yield l(`${this.LINKEDIN_BASE_URL}/rest/images?action=initializeUpload`,{method:"POST",headers:{"LinkedIn-Version":this.LINKEDIN_VERSION,Authorization:`Bearer ${this.accessToken}`,"X-Restli-Protocol-Version":"2.0.0"},data:{initializeUploadRequest:{owner:t}}})).data}catch(o){if(o instanceof u){console.error("Cannot create image upload request. Error: ",(e=o.response)==null?void 0:e.data);return}console.error("Something went wrong. Error: ",o)}})}uploadImage(t,e){return s(this,null,function*(){let o=new Blob([t]);try{let r=yield l(e,{method:"PUT",headers:{"Content-Type":"application/octet-stream",Authorization:`Bearer ${this.accessToken}`},data:o});return r.status!==201?(console.error("Image not created. Status code: ",r.status),!1):!0}catch(r){if(r instanceof u){console.error("Cannot upload image. Error: ",r.cause);return}console.error("Something went wrong. Error: ",r)}})}createPostWithImage(t,e,o){return s(this,null,function*(){var a;let r=yield this.getPersonURN();if(!r){console.error("Cannot get person URN");return}let i=yield this.createImageUploadRequest(r);if(!i){console.error("Cannot create image upload request");return}if(!(yield this.uploadImage(e,i.value.uploadUrl))){console.error("Cannot upload the image");return}let c=i.value.image;try{let n={author:r,commentary:t,visibility:"PUBLIC",distribution:{feedDistribution:"MAIN_FEED",targetEntities:[],thirdPartyDistributionChannels:[]},content:{media:{title:o!=null?o:"Cover image of the post",id:c}},lifecycleState:"PUBLISHED",isReshareDisabledByAuthor:!1},g=yield l(`${this.LINKEDIN_BASE_URL}/rest/posts`,{method:"POST",headers:{"LinkedIn-Version":this.LINKEDIN_VERSION,Authorization:`Bearer ${this.accessToken}`,"Content-Type":"application/json","X-Restli-Protocol-Version":"2.0.0"},data:n});return g.status!==201?(console.error("Image not created. Status code: ",g.status),!1):!0}catch(n){if(n instanceof u){console.error("Cannot create post. Error: ",(a=n.response)==null?void 0:a.data);return}console.error("Something went wrong. Error: ",n)}})}};export{d as default}; | ||
var s=(p,r,e)=>new Promise((t,n)=>{var i=o=>{try{c(e.next(o))}catch(a){n(a)}},h=o=>{try{c(e.throw(o))}catch(a){n(a)}},c=o=>o.done?t(o.value):Promise.resolve(o.value).then(i,h);c((e=e.apply(p,r)).next())});import l,{AxiosError as u}from"axios";var d=class{constructor(r){this.accessToken=r;this.LINKEDIN_BASE_URL="https://api.linkedin.com";this.LINKEDIN_VERSION="202303"}getProfileData(){return s(this,null,function*(){var r;try{return(yield l(`${this.LINKEDIN_BASE_URL}/v2/me`,{method:"GET",headers:{Authorization:`Bearer ${this.accessToken}`}})).data}catch(e){return e instanceof u?(console.error("Cannot get profile data. Error: ",(r=e.response)==null?void 0:r.data),null):(console.error("Something went wrong. Error: ",e),null)}})}getPersonURN(){return s(this,null,function*(){let r=yield this.getProfileData();return!r||!r.id?null:`urn:li:person:${r.id}`})}createImageUploadRequest(r){return s(this,null,function*(){var e;try{return(yield l(`${this.LINKEDIN_BASE_URL}/rest/images?action=initializeUpload`,{method:"POST",headers:{"LinkedIn-Version":this.LINKEDIN_VERSION,Authorization:`Bearer ${this.accessToken}`,"X-Restli-Protocol-Version":"2.0.0"},data:{initializeUploadRequest:{owner:r}}})).data}catch(t){if(t instanceof u){console.error("Cannot create image upload request. Error: ",(e=t.response)==null?void 0:e.data);return}console.error("Something went wrong. Error: ",t)}})}uploadImage(r,e){return s(this,null,function*(){try{let t=yield l(e,{method:"PUT",headers:{"Content-Type":"application/octet-stream",Authorization:`Bearer ${this.accessToken}`},data:r});return t.status!==201?(console.error("Image not created. Status code: ",t.status),!1):!0}catch(t){if(t instanceof u){console.error("Cannot upload image. Error: ",t.cause);return}console.error("Something went wrong. Error: ",t)}})}createPostWithImage(r,e,t){return s(this,null,function*(){var o;let n=yield this.getPersonURN();if(!n){console.error("Cannot get person URN");return}let i=yield this.createImageUploadRequest(n);if(!i){console.error("Cannot create image upload request");return}if(!(yield this.uploadImage(e,i.value.uploadUrl))){console.error("Cannot upload the image");return}let c=i.value.image;try{let a={author:n,commentary:r,visibility:"PUBLIC",distribution:{feedDistribution:"MAIN_FEED",targetEntities:[],thirdPartyDistributionChannels:[]},content:{media:{title:t!=null?t:"Cover image of the post",id:c}},lifecycleState:"PUBLISHED",isReshareDisabledByAuthor:!1},g=yield l(`${this.LINKEDIN_BASE_URL}/rest/posts`,{method:"POST",headers:{"LinkedIn-Version":this.LINKEDIN_VERSION,Authorization:`Bearer ${this.accessToken}`,"Content-Type":"application/json","X-Restli-Protocol-Version":"2.0.0"},data:a});return g.status!==201?(console.error("Image not created. Status code: ",g.status),!1):!0}catch(a){if(a instanceof u){console.error("Cannot create post. Error: ",(o=a.response)==null?void 0:o.data);return}console.error("Something went wrong. Error: ",a)}})}};export{d as default}; |
{ | ||
"name": "linkedin-post-share", | ||
"version": "1.1.12", | ||
"version": "1.1.13", | ||
"description": "A Linkedin Wrapper for Post/Share API. This will help you to post content on linkedin.", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
10272