@corsair-dev/linkedin 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +0 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +10 -4
package/dist/client.d.ts
CHANGED
|
@@ -4,20 +4,6 @@ export declare class LinkedInAPIError extends Error {
|
|
|
4
4
|
readonly retryAfter?: number | undefined;
|
|
5
5
|
constructor(message: string, status?: number | undefined, code?: string | undefined, retryAfter?: number | undefined);
|
|
6
6
|
}
|
|
7
|
-
export type LinkedInTokenSet = {
|
|
8
|
-
accessToken: string;
|
|
9
|
-
refreshToken: string;
|
|
10
|
-
expiresAt: number;
|
|
11
|
-
refreshed: boolean;
|
|
12
|
-
};
|
|
13
|
-
export declare function getValidLinkedInAccessToken({ accessToken, refreshToken, expiresAt, clientId, clientSecret, forceRefresh, }: {
|
|
14
|
-
clientId: string;
|
|
15
|
-
clientSecret: string;
|
|
16
|
-
accessToken: string | null;
|
|
17
|
-
refreshToken: string;
|
|
18
|
-
expiresAt?: number | null;
|
|
19
|
-
forceRefresh?: boolean;
|
|
20
|
-
}): Promise<LinkedInTokenSet>;
|
|
21
7
|
export type LinkedInRequestOptions = {
|
|
22
8
|
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
23
9
|
body?: Record<string, unknown>;
|
|
@@ -28,7 +14,6 @@ export type LinkedInRequestContext = {
|
|
|
28
14
|
key: string;
|
|
29
15
|
_refreshAuth?: () => Promise<string>;
|
|
30
16
|
};
|
|
31
|
-
export declare function attachLinkedInRefreshAuth(ctx: object, refreshAuth: () => Promise<string>): void;
|
|
32
17
|
/**
|
|
33
18
|
* Wrapper around makeLinkedInRequest that retries once on 401 by force-refreshing
|
|
34
19
|
* the access token. Handles tokens that are rejected by LinkedIn even though the
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../client.ts"],"names":[],"mappings":"AAGA,qBAAa,gBAAiB,SAAQ,KAAK;aAGzB,MAAM,CAAC,EAAE,MAAM;aACf,IAAI,CAAC,EAAE,MAAM;aAGb,UAAU,CAAC,EAAE,MAAM;gBALnC,OAAO,EAAE,MAAM,EACC,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,IAAI,CAAC,EAAE,MAAM,YAAA,EAGb,UAAU,CAAC,EAAE,MAAM,YAAA;CAKpC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../client.ts"],"names":[],"mappings":"AAGA,qBAAa,gBAAiB,SAAQ,KAAK;aAGzB,MAAM,CAAC,EAAE,MAAM;aACf,IAAI,CAAC,EAAE,MAAM;aAGb,UAAU,CAAC,EAAE,MAAM;gBALnC,OAAO,EAAE,MAAM,EACC,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,IAAI,CAAC,EAAE,MAAM,YAAA,EAGb,UAAU,CAAC,EAAE,MAAM,YAAA;CAKpC;AAOD,MAAM,MAAM,sBAAsB,GAAG;IACpC,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAG/B,KAAK,CAAC,EAAE,MAAM,CACb,MAAM,EACN,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAC7D,CAAC;CACF,CAAC;AAMF,wBAAsB,mBAAmB,CAAC,CAAC,EAC1C,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,sBAA2B,GAClC,OAAO,CAAC,CAAC,CAAC,CAoDZ;AAYD,MAAM,MAAM,sBAAsB,GAAG;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CACrC,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,gCAAgC,CAAC,CAAC,EACvD,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,sBAAsB,EAC3B,OAAO,GAAE,sBAA2B,GAClC,OAAO,CAAC,CAAC,CAAC,CAUZ"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,QAAQ,EAER,uBAAuB,EAEvB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,QAAQ,EAER,uBAAuB,EAEvB,MAAM,cAAc,CAAC;AAatB,OAAO,KAAK,EACX,sBAAsB,EACtB,uBAAuB,EACvB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,eAAO,MAAM,kBAAkB;;;;CAMM,CAAC;AAEtC,KAAK,gBAAgB,CAAC,CAAC,SAAS,MAAM,uBAAuB,IAC5D,eAAe,CACd,eAAe,EACf,sBAAsB,CAAC,CAAC,CAAC,EACzB,uBAAuB,CAAC,CAAC,CAAC,CAC1B,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG;IAC/B,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACzC,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACzC,UAAU,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC3C,kBAAkB,EAAE,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;IAC3D,cAAc,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACnD,UAAU,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC3C,eAAe,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;IACrD,aAAa,EAAE,gBAAgB,CAAC,eAAe,CAAC,CAAC;IACjD,aAAa,EAAE,gBAAgB,CAAC,eAAe,CAAC,CAAC;IACjD,aAAa,EAAE,gBAAgB,CAAC,eAAe,CAAC,CAAC;IACjD,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACvC,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACzC,qBAAqB,EAAE,gBAAgB,CAAC,uBAAuB,CAAC,CAAC;IACjE,mBAAmB,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;IAC7D,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACzC,cAAc,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACnD,cAAc,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACnD,eAAe,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;IACrD,aAAa,EAAE,gBAAgB,CAAC,eAAe,CAAC,CAAC;IACjD,oBAAoB,EAAE,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;IAC/D,iBAAiB,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;IACzD,yBAAyB,EAAE,gBAAgB,CAAC,2BAA2B,CAAC,CAAC;CACzE,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8C1B,CAAC;AAEX,MAAM,MAAM,sBAAsB,GAAG,aAAa,CACjD,OAAO,uBAAuB,CAC9B,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyFnC,CAAC;AAgGF,MAAM,MAAM,qBAAqB,GAAG;IACnC,QAAQ,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC,CAAC;IACxC,WAAW,CAAC,EAAE,uBAAuB,CAAC,OAAO,uBAAuB,CAAC,CAAC;IACtE,aAAa,CAAC,EAAE,mBAAmB,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,oBAAoB,CACjD,OAAO,cAAc,EACrB,qBAAqB,EACrB,SAAS,EACT,OAAO,kBAAkB,CACzB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,iBAAiB,CACxD,qBAAqB,EACrB,OAAO,kBAAkB,CACzB,CAAC;AAEF,QAAA,MAAM,eAAe,EAAG,SAAkB,CAAC;AAE3C,QAAA,MAAM,sBAAsB,IAAc,CAAC;AAE3C,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,qBAAqB,IAAI,aAAa,CAC9E,UAAU,EACV,OAAO,cAAc,EACrB,OAAO,uBAAuB,EAC9B,OAAO,sBAAsB,EAC7B,CAAC,EACD,OAAO,eAAe,EACtB,OAAO,kBAAkB,CACzB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;AAE/E,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,qBAAqB,IACjE,kBAAkB,CAAC,CAAC,CAAC,CAAC;AAEvB,wBAAgB,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,qBAAqB,EAG7D,eAAe,GAAE,qBAAqB,GAAG,CAAmC,GAC1E,sBAAsB,CAAC,CAAC,CAAC,CAyD3B"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AuthMissingError as me}from"corsair/core";import{ApiError as G,request as he}from"corsair/http";var l=class extends Error{constructor(i,o,d,c){super(i);this.status=o;this.code=d;this.retryAfter=c;this.name="LinkedInAPIError"}},Ie="https://api.linkedin.com",fe="202501",ke="https://www.linkedin.com/oauth/v2/accessToken",be=1440*60;async function ye(n,t,i){let o=await fetch(ke,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:i,client_id:n,client_secret:t})});if(!o.ok){let d=await o.text();throw new l(`Failed to refresh LinkedIn access token: ${d}`,o.status)}return await o.json()}async function C({accessToken:n,refreshToken:t,expiresAt:i,clientId:o,clientSecret:d,forceRefresh:c=!1}){let u=Math.floor(Date.now()/1e3);if(!c&&n&&i&&i>u+be)return{accessToken:n,refreshToken:t,expiresAt:i,refreshed:!1};let I=await ye(o,d,t);return{accessToken:I.access_token,refreshToken:I.refresh_token??t,expiresAt:u+I.expires_in,refreshed:!0}}var U=2048;async function v(n,t,i={}){if(n.length>U)throw new l(`LinkedIn endpoint exceeds ${U} characters`);let{method:o="GET",body:d,query:c}=i,u={BASE:Ie,VERSION:"1.0.0",WITH_CREDENTIALS:!1,CREDENTIALS:"omit",TOKEN:t,HEADERS:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,"X-Restli-Protocol-Version":"2.0.0","LinkedIn-Version":fe}},I={method:o,url:n,body:o==="POST"||o==="PUT"||o==="PATCH"?d:void 0,mediaType:"application/json; charset=utf-8",query:o==="GET"?c:void 0};try{return await he(u,I)}catch(m){throw m instanceof G?new l(m.message,m.status,void 0,m.retryAfter):m instanceof Error?new l(m.message):new l("Unknown LinkedIn API error")}}function Le(n){return n instanceof l||n instanceof G?n.status===401:!1}function O(n,t){Object.assign(n,{_refreshAuth:t})}async function r(n,t,i={}){try{return await v(n,t.key,i)}catch(o){if(Le(o)&&t._refreshAuth){let d=await t._refreshAuth();return await v(n,d,i)}throw o}}import{logEventFromContext as A}from"corsair/core";var z=async(n,t)=>{let i=await r("/v2/adTargetingFacets",n,{method:"GET"});return await A(n,"linkedin.ads.getTargetingFacets",{...t},"completed"),i},N=async(n,t)=>{let i=await r("/v2/audienceCounts",n,{method:"POST",body:{target:t.target}});return await A(n,"linkedin.ads.getAudienceCounts",{...t},"completed"),i},D=async(n,t)=>{let i={q:"TYPEAHEAD","typeahead.query.text":t.query};t.type&&(i["typeahead.type"]=t.type);let o=await r("/v2/adTargetingEntities",n,{method:"GET",query:i});return await A(n,"linkedin.ads.searchTargetingEntities",{...t},"completed"),o};import{logEventFromContext as we}from"corsair/core";var x=async(n,t)=>{let i=await r(`/v2/socialActions/${encodeURIComponent(t.commented_on_urn)}/comments`,n,{method:"POST",body:{actor:t.actor,object:t.commented_on_urn,message:{text:t.message}}});return await we(n,"linkedin.comments.create",{...t},"completed"),i};import{logEventFromContext as S}from"corsair/core";var j=async(n,t)=>{let i=await r(`/v2/images/${encodeURIComponent(t.image_urn)}`,n,{method:"GET"});return await S(n,"linkedin.images.get",{...t},"completed"),i},q=async(n,t)=>{let i={};if(t.urns&&t.urns.length>0)i.q="urns",i.urns=t.urns;else if(t.owner)i.q="owner",i.owner=t.owner;else throw new l("getImages requires owner or a non-empty urns list");t.start!==void 0&&(i.start=t.start),t.count!==void 0&&(i.count=t.count);let o=await r("/v2/images",n,{method:"GET",query:i});return await S(n,"linkedin.images.list",{...t},"completed"),o},F=async(n,t)=>{let i=await r("/rest/images?action=initializeUpload",n,{method:"POST",body:{initializeUploadRequest:{owner:t.owner}}});return await S(n,"linkedin.images.initializeUpload",{...t},"completed"),i},M=async(n,t)=>{let i={registerUploadRequest:{recipes:["urn:li:digitalmediaRecipe:feedshare-image"],owner:t.owner,serviceRelationships:[{relationshipType:"OWNER",identifier:"urn:li:userGeneratedContent"}]}},o=await r("/v2/assets?action=registerUpload",n,{method:"POST",body:i});return await S(n,"linkedin.images.registerUpload",{...t},"completed"),o};import{logEventFromContext as R}from"corsair/core";var B=async(n,t)=>{let i=t.role_assignee;if(!i){let c=await r("/v2/userinfo",n,{method:"GET"}),u=c.sub??c.id;if(!u)throw new l("Could not determine the authenticated member id to list organizations.");i=`urn:li:person:${u}`}let o={q:"roleAssignee",roleAssignee:i,state:t.state??"APPROVED"};t.role&&t.role.length>0&&(o.role=t.role),t.start!==void 0&&(o.start=t.start),t.count!==void 0&&(o.count=t.count);let d=await r("/v2/organizationAcls",n,{method:"GET",query:o});return await R(n,"linkedin.organizations.getCompanyInfo",{...t},"completed"),d},V=async(n,t)=>{let i=await r("/v2/organizationalEntityFollowerStatistics",n,{method:"GET",query:{q:"organizationHandle",organization:t.organization_urn}}),o=i.elements?.[0],d=o?.totalFollowerCount,c=o?.organizationFollowerCount;return await R(n,"linkedin.organizations.getNetworkSize",{...t},"completed"),{totalFollowerCount:typeof d=="number"?d:void 0,organizationFollowerCount:typeof c=="number"?c:void 0,elements:i.elements}},H=async(n,t)=>{let i={q:"organization",organization:t.organization_urn};t.start!==void 0&&(i.start=t.start),t.count!==void 0&&(i.count=t.count),t.time_integrated?.start&&t.time_integrated?.end&&(i.timeIntervals=`(timeDuration:(start:${t.time_integrated.start},end:${t.time_integrated.end}))`);let o=await r("/v2/organizationPageStatistics",n,{method:"GET",query:i});return await R(n,"linkedin.organizations.getPageStats",{...t},"completed"),o},K=async(n,t)=>{let i={q:"organization",organization:t.organization_urn};t.start!==void 0&&(i.start=t.start),t.count!==void 0&&(i.count=t.count),t.time_integrated?.start&&t.time_integrated?.end&&(i.timeIntervals=`(timeDuration:(start:${t.time_integrated.start},end:${t.time_integrated.end}))`);let o=await r("/v2/organizationalEntityShareStatistics",n,{method:"GET",query:i});return await R(n,"linkedin.organizations.getShareStats",{...t},"completed"),o};import{logEventFromContext as y}from"corsair/core";var $=async(n,t)=>{let i={author:t.author,commentary:t.commentary,visibility:t.visibility??"PUBLIC",lifecycleState:t.lifecycleState??"PUBLISHED"};t.isReshareDisabledByAuthor!==void 0&&(i.isReshareDisabledByAuthor=t.isReshareDisabledByAuthor);let o={};if(t.article_url){let c={source:t.article_url};t.article_title&&(c.title=t.article_title),t.article_description&&(c.description=t.article_description),o.article=c}t.image_urn&&(o.media={id:t.image_urn}),Object.keys(o).length>0&&(i.content=o);let d=await r("/rest/posts",n,{method:"POST",body:i});return await y(n,"linkedin.posts.create",{...t},"completed"),d},Q=async(n,t)=>{let i={originalUrl:t.article_url};t.article_title&&(i.title={text:t.article_title}),t.article_description&&(i.description={text:t.article_description}),t.article_thumbnail&&(i.thumbnail=t.article_thumbnail);let o={author:t.authorUrn,lifecycleState:t.lifecycleState??"PUBLISHED",specificContent:{"com.linkedin.ugc.ShareContent":{shareCommentary:{text:t.text??""},shareMediaCategory:"ARTICLE",media:[i]}},visibility:{"com.linkedin.ugc.MemberNetworkVisibility":t.visibility??"PUBLIC"}},d=await r("/v2/ugcPosts",n,{method:"POST",body:o});return await y(n,"linkedin.posts.createArticleShare",{...t},"completed"),d},W=async(n,t)=>{let i=await r(`/rest/posts/${encodeURIComponent(t.post_urn)}`,n,{method:"GET"});return await y(n,"linkedin.posts.getContent",{...t},"completed"),i},X=async(n,t)=>(await r(`/rest/posts/${encodeURIComponent(t.post_id)}`,n,{method:"DELETE"}),await y(n,"linkedin.posts.delete",{...t},"completed"),{success:!0}),Y=async(n,t)=>(await r(`/v2/shares/${encodeURIComponent(t.share_id)}`,n,{method:"DELETE"}),await y(n,"linkedin.posts.deleteShare",{...t},"completed"),{success:!0}),Z=async(n,t)=>(await r(`/v2/ugcPosts/${encodeURIComponent(t.ugc_post_urn)}`,n,{method:"DELETE"}),await y(n,"linkedin.posts.deleteUgc",{...t},"completed"),{success:!0});import{logEventFromContext as J}from"corsair/core";var ee=async(n,t)=>{let i=await r("/v2/userinfo",n,{method:"GET",query:t.projection?{projection:t.projection}:void 0}),o=i.sub??i.id;if(o&&n.db.users)try{await n.db.users.upsertByEntityId(o,{id:o,sub:i.sub,name:i.name,given_name:i.given_name,family_name:i.family_name,picture:i.picture,email:i.email,locale:i.locale,vanityName:i.vanityName,headline:i.headline})}catch{}return await J(n,"linkedin.profile.getMyInfo",{...t},"completed"),i},te=async(n,t)=>{let i=await r(`/v2/people/${encodeURIComponent(t.person_id)}`,n,{method:"GET",query:t.projection?{projection:t.projection}:void 0});return await J(n,"linkedin.profile.getPerson",{...t},"completed"),i};import{logEventFromContext as Te}from"corsair/core";var ne=async(n,t)=>{let i=await r(`/v2/socialActions/${encodeURIComponent(t.entity_urn)}/reactions`,n,{method:"GET",query:{start:t.start,count:t.count}});return await Te(n,"linkedin.reactions.list",{...t},"completed"),i};import{logEventFromContext as Ue}from"corsair/core";var ie=async(n,t)=>{let i={};if(t.video_urn)i.q="urns",i.urns=t.video_urn;else if(t.urns&&t.urns.length>0)i.q="urns",i.urns=t.urns;else if(t.owner)i.q="owner",i.owner=t.owner;else throw new l("getVideos requires video_urn, owner, or a non-empty urns list");t.start!==void 0&&(i.start=t.start),t.count!==void 0&&(i.count=t.count);let o=await r("/v2/videos",n,{method:"GET",query:i});return await Ue(n,"linkedin.videos.list",{...t},"completed"),o};import{z as e}from"zod";var f=e.object({start:e.number().optional(),count:e.number().optional(),total:e.number().optional(),links:e.array(e.record(e.string(),e.unknown())).optional()}).optional(),g=e.string().describe("A LinkedIn URN, e.g. urn:li:person:123, urn:li:organization:456, or urn:li:ugcPost:789."),Ge=e.object({projection:e.string().optional().describe('Optional projection of profile fields to return (e.g. "(sub,name,email)").')}).describe("Fetch the authenticated LinkedIn member's profile (name, headline, profile picture)."),Oe=e.object({person_id:e.string().describe("The LinkedIn member ID of the person whose profile to retrieve."),projection:e.string().optional().describe("Optional projection of fields. Defaults to the lite profile; add headline and vanityName for the basic profile (requires r_basicprofile).")}).describe("Retrieve a LinkedIn member profile by person ID."),ze=e.object({author:g.describe("Author URN. Use urn:li:person:... to post as a person (w_member_social) or urn:li:organization:... to post as an organization (w_organization_social)."),commentary:e.string().describe("The text commentary (body) of the post."),visibility:e.enum(["PUBLIC","CONNECTIONS","LOGGED_IN_MEMBERS"]).optional().describe("Who can see the post. Defaults to PUBLIC."),lifecycleState:e.enum(["PUBLISHED","DRAFT"]).optional().describe("PUBLISHED to post immediately, DRAFT to save as a draft."),isReshareDisabledByAuthor:e.boolean().optional().describe("When true, other members cannot reshare this post."),article_url:e.string().optional().describe("Optional URL to attach as article content with the post."),article_title:e.string().optional().describe("Title for the attached article. Requires article_url."),article_description:e.string().optional().describe("Description for the attached article. Requires article_url."),image_urn:g.optional().describe("Optional image URN to attach as media.")}).refine(n=>!(n.article_url&&n.image_urn),{message:"A post can attach either an article (article_url) or an image (image_urn), not both."}).describe("Create a new LinkedIn post for a member or organization."),Ne=e.object({authorUrn:g.describe("Author URN, e.g. urn:li:person:... or urn:li:organization:...."),text:e.string().optional().describe("Optional commentary to include alongside the shared URL."),article_url:e.string().describe("The URL to share as an article."),article_title:e.string().optional().describe("Optional title for the article."),article_description:e.string().optional().describe("Optional description for the article."),article_thumbnail:e.string().optional().describe("Optional thumbnail URL for the article."),visibility:e.enum(["PUBLIC","CONNECTIONS"]).optional().describe("Visibility of the share. Defaults to PUBLIC."),lifecycleState:e.enum(["PUBLISHED","DRAFT"]).optional().describe("PUBLISHED to post immediately, DRAFT to save as a draft.")}).describe("Create an article or URL share on LinkedIn via the UGC Posts API."),De=e.object({post_urn:e.string().describe("The post URN (e.g. urn:li:post:1234567890) whose content to retrieve.")}).describe("Retrieve detailed content of a specific LinkedIn post."),xe=e.object({post_id:e.string().describe("The post URN or ID to delete via the Posts API (idempotent, returns 204).")}).describe("Delete a LinkedIn post using the Posts API REST endpoint."),je=e.object({share_id:e.string().describe("The share ID of the LinkedIn share to delete.")}).describe("Delete a specific LinkedIn post (share) by its share_id."),qe=e.object({ugc_post_urn:e.string().describe("The UGC post URN (e.g. urn:li:ugcPost:12345) to delete.")}).describe("Delete a UGC post using the legacy v2/ugcPosts endpoint (idempotent)."),Fe=e.object({commented_on_urn:e.string().describe("URN of the object being commented on: a share, UGC post, or parent comment."),actor:g.describe("URN of the member or organization posting the comment, e.g. urn:li:person:... or urn:li:organization:...."),message:e.string().describe("The text of the comment (max 3000 characters).")}).describe("Create a first-level or nested comment on a LinkedIn share, UGC post, or comment."),Me=e.object({entity_urn:e.string().describe("URN of the entity (share, post, or comment) whose reactions to list."),start:e.number().optional().describe("Pagination start index. Defaults to 0."),count:e.number().optional().describe("Number of reactions to return per page.")}).describe("Retrieve reactions (likes, celebrations, etc.) on a LinkedIn entity."),Be=e.object({image_urn:e.string().describe("The image URN (e.g. urn:li:image:C4D22...) whose details to retrieve.")}).describe("Retrieve details of a single LinkedIn image by its URN."),Ve=e.object({owner:g.optional().describe("Owner URN. Returns images owned by this member/org."),urns:e.array(e.string()).optional().describe("Specific image URNs to fetch in a single batch request."),start:e.number().optional().describe("Pagination start index."),count:e.number().optional().describe("Number of images per page.")}).refine(n=>!!(n.owner||n.urns&&n.urns.length>0),{message:"getImages requires owner or a non-empty urns list \u2014 LinkedIn rejects /v2/images without a q finder."}).describe("Retrieve LinkedIn image metadata (download URLs, status, dimensions)."),He=e.object({owner:g.describe("Owner URN that will own the uploaded image, e.g. urn:li:person:... or urn:li:organization:....")}).describe("Initialize a LinkedIn image upload and return a presigned upload URL plus the image URN."),Ke=e.object({owner:g.describe("Owner URN for the media asset, e.g. urn:li:person:... or urn:li:organization:....")}).describe("Register a native LinkedIn image upload for feed shares and return a presigned upload URL plus the digital media asset URN."),$e=e.object({video_urn:e.string().optional().describe("A single video URN to retrieve."),owner:g.optional().describe("Owner URN. Returns videos owned by this account."),urns:e.array(e.string()).optional().describe("Specific video URNs to fetch in a batch."),start:e.number().optional().describe("Pagination start index."),count:e.number().optional().describe("Number of videos per page.")}).refine(n=>!!(n.video_urn||n.owner||n.urns&&n.urns.length>0),{message:"getVideos requires video_urn, owner, or a non-empty urns list \u2014 LinkedIn rejects /v2/videos without a q finder."}).describe("Retrieve LinkedIn video metadata (duration, dimensions, download URLs)."),Qe=e.object({role_assignee:g.optional().describe("Person URN whose organization roles to list. Defaults to the authenticated member."),role:e.array(e.enum(["ADMINISTRATOR","DIRECT_SPONSORED_CONTENT_POSTER","RECRUITING_POSTER","LEAD_GEN_FORMS_MANAGER","CONTENT_ADMIN","ANALYTICS_ROLE"])).optional().describe("Filter to specific organization roles."),state:e.enum(["APPROVED","PENDING","REVOKED"]).optional().describe("Filter to ACLs in a given state. Defaults to APPROVED."),start:e.number().int().min(0).optional().describe("Zero-based pagination offset into the role list."),count:e.number().int().min(1).optional().describe("Maximum number of roles to return per page.")}).describe("Retrieve organizations where the authenticated user has specific roles (ACLs)."),We=e.object({organization_urn:g.describe("The organization URN (e.g. urn:li:organization:2414183) whose follower count to retrieve.")}).describe("Retrieve the follower count for a LinkedIn organization."),Xe=e.object({organization_urn:g.describe("The organization URN whose page statistics to retrieve."),time_integrated:e.object({start:e.number().optional(),end:e.number().optional()}).optional().describe("Optional time range for time-bound (aggregate) statistics."),start:e.number().optional().describe("Pagination start index."),count:e.number().optional().describe("Number of results per page.")}).describe("Retrieve page statistics (page views, custom button clicks) for a LinkedIn organization."),Ye=e.object({organization_urn:g.describe("The organization URN whose share statistics to retrieve."),time_integrated:e.object({start:e.number().optional(),end:e.number().optional()}).optional().describe("Optional time range to filter statistics."),start:e.number().optional().describe("Pagination start index."),count:e.number().optional().describe("Number of results per page.")}).describe("Retrieve share statistics (impressions, clicks, likes, comments, shares) for an organization."),Ze=e.object({}).describe("Retrieve available ad targeting facets from the LinkedIn Marketing API (locations, industries, job functions, etc.)."),Je=e.object({target:e.record(e.string(),e.unknown()).describe("Targeting criteria to estimate audience size for, as a LinkedIn targeting object (e.g. { and: [ { or: [...] }] }).")}).describe("Retrieve audience size counts for specified targeting criteria."),et=e.object({query:e.string().describe("Typeahead search query for targeting entities."),type:e.string().optional().describe("Optional facet type to scope the search (e.g. locations, titles, industries).")}).describe("Search ad targeting entities (geographies, job titles, industries) via typeahead search."),s={GetMyInfo:Ge,GetPerson:Oe,CreatePost:ze,CreateArticleShare:Ne,GetPostContent:De,DeletePost:xe,DeleteSharePost:je,DeleteUgcPost:qe,CreateComment:Fe,ListReactions:Me,GetImage:Be,GetImages:Ve,InitializeImageUpload:He,RegisterImageUpload:Ke,GetVideos:$e,GetCompanyInfo:Qe,GetNetworkSize:We,GetOrgPageStats:Xe,GetShareStats:Ye,GetAdTargetingFacets:Ze,GetAudienceCounts:Je,SearchAdTargetingEntities:et},tt=e.object({sub:e.string().optional(),id:e.string().optional(),name:e.string().nullable().optional(),given_name:e.string().nullable().optional(),family_name:e.string().nullable().optional(),picture:e.string().nullable().optional(),email:e.string().nullable().optional(),locale:e.string().nullable().optional(),vanityName:e.string().optional(),headline:e.string().optional()}).loose().describe("The authenticated LinkedIn member profile."),nt=e.object({id:e.string().describe("The member ID."),localizedFirstName:e.string().optional(),localizedLastName:e.string().optional(),localizedHeadline:e.string().optional(),vanityName:e.string().optional(),firstName:e.record(e.string(),e.unknown()).optional(),lastName:e.record(e.string(),e.unknown()).optional(),headline:e.record(e.string(),e.unknown()).optional(),profilePicture:e.object({"displayImage~":e.string().optional(),"displayImage~:playableStreams":e.array(e.record(e.string(),e.unknown())).optional()}).loose().optional()}).loose(),it=e.object({id:e.string().describe("The URN of the newly created post.")}).describe("Result of creating a LinkedIn post."),ot=e.object({id:e.string().describe("The URN of the newly created UGC post."),activity:e.string().optional()}).describe("Result of creating an article/URL share."),rt=e.object({id:e.string(),author:e.string().optional(),commentary:e.string().optional(),visibility:e.string().optional(),lifecycleState:e.string().optional(),createdAt:e.record(e.string(),e.unknown()).optional(),isReshareDisabledByAuthor:e.boolean().optional(),media:e.record(e.string(),e.unknown()).optional(),content:e.record(e.string(),e.unknown()).optional()}).loose().describe("Detailed content of a LinkedIn post."),T=e.object({success:e.boolean().describe("Whether the delete operation completed.")}).describe("Result of deleting a post."),st=e.object({id:e.string().optional().describe("The URN of the created comment."),message:e.string().optional().describe("The comment text."),object:e.string().optional().describe("The URN the comment was posted on."),lastModified:e.record(e.string(),e.unknown()).optional()}).loose().describe("Result of creating a comment."),at=e.object({actor:e.string().optional().describe("URN of the member who reacted."),type:e.string().optional().describe("Reaction type, e.g. LIKE, CELEBRATION."),created:e.record(e.string(),e.unknown()).optional()}).loose(),dt=e.object({elements:e.array(at).describe("The reactions on the entity."),paging:f}).loose().describe("Reactions on a LinkedIn entity."),oe=e.object({id:e.string().describe("The image URN."),owner:e.string().optional(),status:e.string().optional().describe("UPLOADING, AVAILABLE, WAITING_UPLOAD, etc."),downloadUrl:e.string().nullable().optional(),original:e.object({size:e.string().optional(),width:e.number().optional(),height:e.number().optional()}).loose().optional()}).loose(),ct=oe,lt=e.object({elements:e.array(oe),paging:f}).loose(),pt=e.object({value:e.object({image:e.string().describe("The new image URN to use when attaching the image to a post."),uploadUrl:e.string().optional().describe("Presigned URL to PUT the image bytes to."),uploadUrlExpiresAt:e.number().optional().describe("Epoch millis when the upload URL expires.")}).loose()}).loose().describe("Result of initializing an image upload."),gt=e.object({value:e.object({asset:e.string().describe("The digital media asset URN to reference in a post."),mediaArtifact:e.string().optional(),uploadMechanism:e.record(e.string(),e.unknown()).optional().describe("Contains the uploadUrl under com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest.")}).loose()}).loose().describe("Result of registering an image upload."),ut=e.object({id:e.string().describe("The video URN."),owner:e.string().optional(),status:e.string().optional().describe("UPLOADING, AVAILABLE, etc."),downloadUrl:e.string().nullable().optional(),durationMilliseconds:e.number().optional(),original:e.object({width:e.number().optional(),height:e.number().optional()}).loose().optional()}).loose(),mt=e.object({elements:e.array(ut),paging:f}).loose(),ht=e.object({organization:e.string().optional().describe("Organization URN."),organizationRoleAssignee:e.string().optional(),role:e.string().optional().describe("The role held, e.g. ADMINISTRATOR."),state:e.string().optional()}).loose(),It=e.object({elements:e.array(ht),paging:f}).loose(),ft=e.object({totalFollowerCount:e.number().optional().describe("Total followers of the organization."),organizationFollowerCount:e.number().optional(),elements:e.array(e.record(e.string(),e.unknown())).optional(),paging:f}).loose().describe("Follower count for a LinkedIn organization."),re=e.record(e.string(),e.unknown()),kt=e.object({elements:e.array(re).describe("Page statistics entries."),paging:f}).loose(),bt=e.object({elements:e.array(re).describe("Share statistics entries."),paging:f}).loose(),yt=e.object({facets:e.array(e.record(e.string(),e.unknown())).optional().describe("Available targeting facets."),elements:e.array(e.record(e.string(),e.unknown())).optional()}).loose(),Lt=e.object({elements:e.array(e.record(e.string(),e.unknown())).optional().describe("Audience size entries for the given targeting criteria."),paging:f}).loose(),Et=e.object({elements:e.array(e.record(e.string(),e.unknown())).optional().describe("Matching targeting entities."),paging:f}).loose(),a={GetMyInfo:tt,GetPerson:nt,CreatePost:it,CreateArticleShare:ot,GetPostContent:rt,DeletePost:T,DeleteSharePost:T,DeleteUgcPost:T,CreateComment:st,ListReactions:dt,GetImage:ct,GetImages:lt,InitializeImageUpload:pt,RegisterImageUpload:gt,GetVideos:mt,GetCompanyInfo:It,GetNetworkSize:ft,GetOrgPageStats:kt,GetShareStats:bt,GetAdTargetingFacets:yt,GetAudienceCounts:Lt,SearchAdTargetingEntities:Et};var _={getMyInfo:ee,getPerson:te},k={create:$,createArticleShare:Q,getContent:W,delete:X,deleteShare:Y,deleteUgc:Z},se={create:x},ae={list:ne},E={get:j,list:q,initializeUpload:F,registerUpload:M},de={list:ie},w={getCompanyInfo:B,getNetworkSize:V,getPageStats:H,getShareStats:K},P={getTargetingFacets:z,getAudienceCounts:N,searchTargetingEntities:D};import{ApiError as le}from"corsair/http";function ce(n){if(n instanceof l||n instanceof le)return n.status}var pe={RATE_LIMIT_ERROR:{match:n=>{if(ce(n)===429)return!0;let t=n.message.toLowerCase();return t.includes("rate_limited")||t.includes("too many requests")||t.includes("429")},handler:async n=>{let t;return(n instanceof l&&n.retryAfter!==void 0||n instanceof le&&n.retryAfter!==void 0)&&(t=n.retryAfter),{maxRetries:5,headersRetryAfterMs:t}}},AUTH_ERROR:{match:n=>{if(ce(n)===401)return!0;let t=n.message.toLowerCase();return t.includes("unauthorized")||t.includes("invalid_auth")},handler:async()=>({maxRetries:0})},DEFAULT:{match:()=>!0,handler:async()=>({maxRetries:0})}};import{z as p}from"zod";var ge=p.object({id:p.string().describe("The LinkedIn member ID of the authenticated user."),sub:p.string().optional().describe("The OIDC subject identifier."),name:p.string().nullable().optional().describe("Display name of the member."),given_name:p.string().nullable().optional().describe("First name."),family_name:p.string().nullable().optional().describe("Last name."),picture:p.string().nullable().optional().describe("Profile picture URL."),email:p.string().nullable().optional().describe("Primary email address."),locale:p.string().nullable().optional().describe("Preferred locale."),headline:p.string().nullable().optional().describe("Profile headline."),vanityName:p.string().nullable().optional().describe("Public vanity name."),createdAt:p.coerce.date().nullable().optional(),updatedAt:p.coerce.date().nullable().optional()});var ue={version:"1.0.0",entities:{users:ge}};var wt={oauth_2:{integration:[]}},St={profile:{getMyInfo:_.getMyInfo,getPerson:_.getPerson},posts:{create:k.create,createArticleShare:k.createArticleShare,getContent:k.getContent,delete:k.delete,deleteShare:k.deleteShare,deleteUgc:k.deleteUgc},comments:{create:se.create},reactions:{list:ae.list},images:{get:E.get,list:E.list,initializeUpload:E.initializeUpload,registerUpload:E.registerUpload},videos:{list:de.list},organizations:{getCompanyInfo:w.getCompanyInfo,getNetworkSize:w.getNetworkSize,getPageStats:w.getPageStats,getShareStats:w.getShareStats},ads:{getTargetingFacets:P.getTargetingFacets,getAudienceCounts:P.getAudienceCounts,searchTargetingEntities:P.searchTargetingEntities}},Rt={"profile.getMyInfo":{input:s.GetMyInfo,output:a.GetMyInfo},"profile.getPerson":{input:s.GetPerson,output:a.GetPerson},"posts.create":{input:s.CreatePost,output:a.CreatePost},"posts.createArticleShare":{input:s.CreateArticleShare,output:a.CreateArticleShare},"posts.getContent":{input:s.GetPostContent,output:a.GetPostContent},"posts.delete":{input:s.DeletePost,output:a.DeletePost},"posts.deleteShare":{input:s.DeleteSharePost,output:a.DeleteSharePost},"posts.deleteUgc":{input:s.DeleteUgcPost,output:a.DeleteUgcPost},"comments.create":{input:s.CreateComment,output:a.CreateComment},"reactions.list":{input:s.ListReactions,output:a.ListReactions},"images.get":{input:s.GetImage,output:a.GetImage},"images.list":{input:s.GetImages,output:a.GetImages},"images.initializeUpload":{input:s.InitializeImageUpload,output:a.InitializeImageUpload},"images.registerUpload":{input:s.RegisterImageUpload,output:a.RegisterImageUpload},"videos.list":{input:s.GetVideos,output:a.GetVideos},"organizations.getCompanyInfo":{input:s.GetCompanyInfo,output:a.GetCompanyInfo},"organizations.getNetworkSize":{input:s.GetNetworkSize,output:a.GetNetworkSize},"organizations.getPageStats":{input:s.GetOrgPageStats,output:a.GetOrgPageStats},"organizations.getShareStats":{input:s.GetShareStats,output:a.GetShareStats},"ads.getTargetingFacets":{input:s.GetAdTargetingFacets,output:a.GetAdTargetingFacets},"ads.getAudienceCounts":{input:s.GetAudienceCounts,output:a.GetAudienceCounts},"ads.searchTargetingEntities":{input:s.SearchAdTargetingEntities,output:a.SearchAdTargetingEntities}},Pt={"profile.getMyInfo":{riskLevel:"read",description:"Fetch the authenticated LinkedIn member's profile."},"profile.getPerson":{riskLevel:"read",description:"Retrieve a LinkedIn member profile by person ID."},"posts.create":{riskLevel:"write",description:"Create a new LinkedIn post for a member or organization."},"posts.createArticleShare":{riskLevel:"write",description:"Create an article or URL share on LinkedIn."},"posts.getContent":{riskLevel:"read",description:"Retrieve detailed content of a specific LinkedIn post."},"posts.delete":{riskLevel:"destructive",irreversible:!0,description:"Delete a LinkedIn post via the Posts API."},"posts.deleteShare":{riskLevel:"destructive",irreversible:!0,description:"Delete a LinkedIn post (share) by its share_id."},"posts.deleteUgc":{riskLevel:"destructive",irreversible:!0,description:"Delete a UGC post via the legacy v2/ugcPosts endpoint."},"comments.create":{riskLevel:"write",description:"Create a comment on a LinkedIn share, UGC post, or comment."},"reactions.list":{riskLevel:"read",description:"List reactions on a LinkedIn entity."},"images.get":{riskLevel:"read",description:"Retrieve details of a single LinkedIn image by URN."},"images.list":{riskLevel:"read",description:"Retrieve LinkedIn image metadata."},"images.initializeUpload":{riskLevel:"write",description:"Initialize a LinkedIn image upload and return an upload URL."},"images.registerUpload":{riskLevel:"write",description:"Register a native image upload for feed shares."},"videos.list":{riskLevel:"read",description:"Retrieve LinkedIn video metadata."},"organizations.getCompanyInfo":{riskLevel:"read",description:"Retrieve organizations where the user has roles."},"organizations.getNetworkSize":{riskLevel:"read",description:"Retrieve the follower count for a LinkedIn organization."},"organizations.getPageStats":{riskLevel:"read",description:"Retrieve page statistics for a LinkedIn organization."},"organizations.getShareStats":{riskLevel:"read",description:"Retrieve share statistics for an organization."},"ads.getTargetingFacets":{riskLevel:"read",description:"Retrieve available LinkedIn ad targeting facets."},"ads.getAudienceCounts":{riskLevel:"read",description:"Retrieve audience size counts for targeting criteria."},"ads.searchTargetingEntities":{riskLevel:"read",description:"Search LinkedIn ad targeting entities via typeahead."}},Ct="oauth_2";function ln(n={}){let t={...n,authType:n.authType??Ct};return{id:"linkedin",schema:ue,options:t,authConfig:wt,oauthConfig:{providerName:"LinkedIn",authUrl:"https://www.linkedin.com/oauth/v2/authorization",tokenUrl:"https://www.linkedin.com/oauth/v2/accessToken",tokenAuthMethod:"body",scopes:["openid","profile","email","r_basicprofile","r_member_social","w_member_social","r_organization_social","w_organization_social","rw_organization_admin","r_organization_admin","r_organization_relationships","r_ads","rw_ads","r_1st_connections_size"]},hooks:t.hooks,endpoints:St,endpointSchemas:Rt,endpointMeta:Pt,errorHandlers:{...pe,...t.errorHandlers},keyBuilder:async i=>{if(t.key)return t.key;if(i.authType!=="oauth_2")throw new me("linkedin","oauth_2");let[o,d,c,u]=await Promise.all([i.keys.get_access_token(),i.keys.get_expires_at(),i.keys.get_refresh_token(),i.keys.get_integration_credentials()]),I=u.client_id,m=u.client_secret;if(!I||!m)throw new Error("[corsair:linkedin] No client id or client secret");if(!c)throw new me("linkedin","oauth_2");let b;try{b=await C({accessToken:o??null,refreshToken:c,expiresAt:d?Number(d):null,clientId:I,clientSecret:m})}catch(h){throw new Error(`[corsair:linkedin] Failed to obtain access token: ${h instanceof Error?h.message:String(h)}`)}if(b.refreshed)try{await i.keys.set_access_token(b.accessToken),await i.keys.set_expires_at(String(b.expiresAt)),await i.keys.set_refresh_token(b.refreshToken)}catch(h){throw new Error(`[corsair:linkedin] Token was refreshed but failed to persist new credentials: ${h instanceof Error?h.message:String(h)}`)}return O(i,async()=>{let h=await i.keys.get_refresh_token()??c,L=await C({accessToken:null,refreshToken:h,expiresAt:null,clientId:I,clientSecret:m,forceRefresh:!0});return await i.keys.set_access_token(L.accessToken),await i.keys.set_expires_at(String(L.expiresAt)),L.refreshToken!==h&&await i.keys.set_refresh_token(L.refreshToken),L.accessToken}),b.accessToken}}}export{Rt as LinkedInEndpointSchemas,St as LinkedInEndpointsNested,ln as linkedin,wt as linkedinAuthConfig};
|
|
1
|
+
import{AuthMissingError as mt,getOAuthAccessToken as ht}from"corsair/core";import{logEventFromContext as S}from"corsair/core";import{ApiError as A,request as ce}from"corsair/http";var d=class extends Error{constructor(i,o,c,p){super(i);this.status=o;this.code=c;this.retryAfter=p;this.name="LinkedInAPIError"}},le="https://api.linkedin.com",pe="202501",w=2048;async function C(n,t,i={}){if(n.length>w)throw new d(`LinkedIn endpoint exceeds ${w} characters`);let{method:o="GET",body:c,query:p}=i,k={BASE:le,VERSION:"1.0.0",WITH_CREDENTIALS:!1,CREDENTIALS:"omit",TOKEN:t,HEADERS:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,"X-Restli-Protocol-Version":"2.0.0","LinkedIn-Version":pe}},de={method:o,url:n,body:o==="POST"||o==="PUT"||o==="PATCH"?c:void 0,mediaType:"application/json; charset=utf-8",query:o==="GET"?p:void 0};try{return await ce(k,de)}catch(h){throw h instanceof A?new d(h.message,h.status,void 0,h.retryAfter):h instanceof Error?new d(h.message):new d("Unknown LinkedIn API error")}}function ge(n){return n instanceof d||n instanceof A?n.status===401:!1}async function r(n,t,i={}){try{return await C(n,t.key,i)}catch(o){if(ge(o)&&t._refreshAuth){let c=await t._refreshAuth();return await C(n,c,i)}throw o}}var T=async(n,t)=>{let i=await r("/v2/adTargetingFacets",n,{method:"GET"});return await S(n,"linkedin.ads.getTargetingFacets",{...t},"completed"),i},U=async(n,t)=>{let i=await r("/v2/audienceCounts",n,{method:"POST",body:{target:t.target}});return await S(n,"linkedin.ads.getAudienceCounts",{...t},"completed"),i},v=async(n,t)=>{let i={q:"TYPEAHEAD","typeahead.query.text":t.query};t.type&&(i["typeahead.type"]=t.type);let o=await r("/v2/adTargetingEntities",n,{method:"GET",query:i});return await S(n,"linkedin.ads.searchTargetingEntities",{...t},"completed"),o};import{logEventFromContext as me}from"corsair/core";var G=async(n,t)=>{let i=await r(`/v2/socialActions/${encodeURIComponent(t.commented_on_urn)}/comments`,n,{method:"POST",body:{actor:t.actor,object:t.commented_on_urn,message:{text:t.message}}});return await me(n,"linkedin.comments.create",{...t},"completed"),i};import{logEventFromContext as y}from"corsair/core";var O=async(n,t)=>{let i=await r(`/v2/images/${encodeURIComponent(t.image_urn)}`,n,{method:"GET"});return await y(n,"linkedin.images.get",{...t},"completed"),i},_=async(n,t)=>{let i={};if(t.urns&&t.urns.length>0)i.q="urns",i.urns=t.urns;else if(t.owner)i.q="owner",i.owner=t.owner;else throw new d("getImages requires owner or a non-empty urns list");t.start!==void 0&&(i.start=t.start),t.count!==void 0&&(i.count=t.count);let o=await r("/v2/images",n,{method:"GET",query:i});return await y(n,"linkedin.images.list",{...t},"completed"),o},z=async(n,t)=>{let i=await r("/rest/images?action=initializeUpload",n,{method:"POST",body:{initializeUploadRequest:{owner:t.owner}}});return await y(n,"linkedin.images.initializeUpload",{...t},"completed"),i},N=async(n,t)=>{let i={registerUploadRequest:{recipes:["urn:li:digitalmediaRecipe:feedshare-image"],owner:t.owner,serviceRelationships:[{relationshipType:"OWNER",identifier:"urn:li:userGeneratedContent"}]}},o=await r("/v2/assets?action=registerUpload",n,{method:"POST",body:i});return await y(n,"linkedin.images.registerUpload",{...t},"completed"),o};import{logEventFromContext as L}from"corsair/core";var D=async(n,t)=>{let i=t.role_assignee;if(!i){let p=await r("/v2/userinfo",n,{method:"GET"}),k=p.sub??p.id;if(!k)throw new d("Could not determine the authenticated member id to list organizations.");i=`urn:li:person:${k}`}let o={q:"roleAssignee",roleAssignee:i,state:t.state??"APPROVED"};t.role&&t.role.length>0&&(o.role=t.role),t.start!==void 0&&(o.start=t.start),t.count!==void 0&&(o.count=t.count);let c=await r("/v2/organizationAcls",n,{method:"GET",query:o});return await L(n,"linkedin.organizations.getCompanyInfo",{...t},"completed"),c},x=async(n,t)=>{let i=await r("/v2/organizationalEntityFollowerStatistics",n,{method:"GET",query:{q:"organizationHandle",organization:t.organization_urn}}),o=i.elements?.[0],c=o?.totalFollowerCount,p=o?.organizationFollowerCount;return await L(n,"linkedin.organizations.getNetworkSize",{...t},"completed"),{totalFollowerCount:typeof c=="number"?c:void 0,organizationFollowerCount:typeof p=="number"?p:void 0,elements:i.elements}},j=async(n,t)=>{let i={q:"organization",organization:t.organization_urn};t.start!==void 0&&(i.start=t.start),t.count!==void 0&&(i.count=t.count),t.time_integrated?.start&&t.time_integrated?.end&&(i.timeIntervals=`(timeDuration:(start:${t.time_integrated.start},end:${t.time_integrated.end}))`);let o=await r("/v2/organizationPageStatistics",n,{method:"GET",query:i});return await L(n,"linkedin.organizations.getPageStats",{...t},"completed"),o},q=async(n,t)=>{let i={q:"organization",organization:t.organization_urn};t.start!==void 0&&(i.start=t.start),t.count!==void 0&&(i.count=t.count),t.time_integrated?.start&&t.time_integrated?.end&&(i.timeIntervals=`(timeDuration:(start:${t.time_integrated.start},end:${t.time_integrated.end}))`);let o=await r("/v2/organizationalEntityShareStatistics",n,{method:"GET",query:i});return await L(n,"linkedin.organizations.getShareStats",{...t},"completed"),o};import{logEventFromContext as I}from"corsair/core";var F=async(n,t)=>{let i={author:t.author,commentary:t.commentary,visibility:t.visibility??"PUBLIC",lifecycleState:t.lifecycleState??"PUBLISHED"};t.isReshareDisabledByAuthor!==void 0&&(i.isReshareDisabledByAuthor=t.isReshareDisabledByAuthor);let o={};if(t.article_url){let p={source:t.article_url};t.article_title&&(p.title=t.article_title),t.article_description&&(p.description=t.article_description),o.article=p}t.image_urn&&(o.media={id:t.image_urn}),Object.keys(o).length>0&&(i.content=o);let c=await r("/rest/posts",n,{method:"POST",body:i});return await I(n,"linkedin.posts.create",{...t},"completed"),c},M=async(n,t)=>{let i={originalUrl:t.article_url};t.article_title&&(i.title={text:t.article_title}),t.article_description&&(i.description={text:t.article_description}),t.article_thumbnail&&(i.thumbnail=t.article_thumbnail);let o={author:t.authorUrn,lifecycleState:t.lifecycleState??"PUBLISHED",specificContent:{"com.linkedin.ugc.ShareContent":{shareCommentary:{text:t.text??""},shareMediaCategory:"ARTICLE",media:[i]}},visibility:{"com.linkedin.ugc.MemberNetworkVisibility":t.visibility??"PUBLIC"}},c=await r("/v2/ugcPosts",n,{method:"POST",body:o});return await I(n,"linkedin.posts.createArticleShare",{...t},"completed"),c},B=async(n,t)=>{let i=await r(`/rest/posts/${encodeURIComponent(t.post_urn)}`,n,{method:"GET"});return await I(n,"linkedin.posts.getContent",{...t},"completed"),i},V=async(n,t)=>(await r(`/rest/posts/${encodeURIComponent(t.post_id)}`,n,{method:"DELETE"}),await I(n,"linkedin.posts.delete",{...t},"completed"),{success:!0}),H=async(n,t)=>(await r(`/v2/shares/${encodeURIComponent(t.share_id)}`,n,{method:"DELETE"}),await I(n,"linkedin.posts.deleteShare",{...t},"completed"),{success:!0}),K=async(n,t)=>(await r(`/v2/ugcPosts/${encodeURIComponent(t.ugc_post_urn)}`,n,{method:"DELETE"}),await I(n,"linkedin.posts.deleteUgc",{...t},"completed"),{success:!0});import{logEventFromContext as $}from"corsair/core";var Q=async(n,t)=>{let i=await r("/v2/userinfo",n,{method:"GET",query:t.projection?{projection:t.projection}:void 0}),o=i.sub??i.id;if(o&&n.db.users)try{await n.db.users.upsertByEntityId(o,{id:o,sub:i.sub,name:i.name,given_name:i.given_name,family_name:i.family_name,picture:i.picture,email:i.email,locale:i.locale,vanityName:i.vanityName,headline:i.headline})}catch{}return await $(n,"linkedin.profile.getMyInfo",{...t},"completed"),i},W=async(n,t)=>{let i=await r(`/v2/people/${encodeURIComponent(t.person_id)}`,n,{method:"GET",query:t.projection?{projection:t.projection}:void 0});return await $(n,"linkedin.profile.getPerson",{...t},"completed"),i};import{logEventFromContext as ye}from"corsair/core";var X=async(n,t)=>{let i=await r(`/v2/socialActions/${encodeURIComponent(t.entity_urn)}/reactions`,n,{method:"GET",query:{start:t.start,count:t.count}});return await ye(n,"linkedin.reactions.list",{...t},"completed"),i};import{logEventFromContext as Ee}from"corsair/core";var Y=async(n,t)=>{let i={};if(t.video_urn)i.q="urns",i.urns=t.video_urn;else if(t.urns&&t.urns.length>0)i.q="urns",i.urns=t.urns;else if(t.owner)i.q="owner",i.owner=t.owner;else throw new d("getVideos requires video_urn, owner, or a non-empty urns list");t.start!==void 0&&(i.start=t.start),t.count!==void 0&&(i.count=t.count);let o=await r("/v2/videos",n,{method:"GET",query:i});return await Ee(n,"linkedin.videos.list",{...t},"completed"),o};import{z as e}from"zod";var u=e.object({start:e.number().optional(),count:e.number().optional(),total:e.number().optional(),links:e.array(e.record(e.string(),e.unknown())).optional()}).optional(),g=e.string().describe("A LinkedIn URN, e.g. urn:li:person:123, urn:li:organization:456, or urn:li:ugcPost:789."),Pe=e.object({projection:e.string().optional().describe('Optional projection of profile fields to return (e.g. "(sub,name,email)").')}).describe("Fetch the authenticated LinkedIn member's profile (name, headline, profile picture)."),Re=e.object({person_id:e.string().describe("The LinkedIn member ID of the person whose profile to retrieve."),projection:e.string().optional().describe("Optional projection of fields. Defaults to the lite profile; add headline and vanityName for the basic profile (requires r_basicprofile).")}).describe("Retrieve a LinkedIn member profile by person ID."),we=e.object({author:g.describe("Author URN. Use urn:li:person:... to post as a person (w_member_social) or urn:li:organization:... to post as an organization (w_organization_social)."),commentary:e.string().describe("The text commentary (body) of the post."),visibility:e.enum(["PUBLIC","CONNECTIONS","LOGGED_IN_MEMBERS"]).optional().describe("Who can see the post. Defaults to PUBLIC."),lifecycleState:e.enum(["PUBLISHED","DRAFT"]).optional().describe("PUBLISHED to post immediately, DRAFT to save as a draft."),isReshareDisabledByAuthor:e.boolean().optional().describe("When true, other members cannot reshare this post."),article_url:e.string().optional().describe("Optional URL to attach as article content with the post."),article_title:e.string().optional().describe("Title for the attached article. Requires article_url."),article_description:e.string().optional().describe("Description for the attached article. Requires article_url."),image_urn:g.optional().describe("Optional image URN to attach as media.")}).refine(n=>!(n.article_url&&n.image_urn),{message:"A post can attach either an article (article_url) or an image (image_urn), not both."}).describe("Create a new LinkedIn post for a member or organization."),Ce=e.object({authorUrn:g.describe("Author URN, e.g. urn:li:person:... or urn:li:organization:...."),text:e.string().optional().describe("Optional commentary to include alongside the shared URL."),article_url:e.string().describe("The URL to share as an article."),article_title:e.string().optional().describe("Optional title for the article."),article_description:e.string().optional().describe("Optional description for the article."),article_thumbnail:e.string().optional().describe("Optional thumbnail URL for the article."),visibility:e.enum(["PUBLIC","CONNECTIONS"]).optional().describe("Visibility of the share. Defaults to PUBLIC."),lifecycleState:e.enum(["PUBLISHED","DRAFT"]).optional().describe("PUBLISHED to post immediately, DRAFT to save as a draft.")}).describe("Create an article or URL share on LinkedIn via the UGC Posts API."),Ae=e.object({post_urn:e.string().describe("The post URN (e.g. urn:li:post:1234567890) whose content to retrieve.")}).describe("Retrieve detailed content of a specific LinkedIn post."),Te=e.object({post_id:e.string().describe("The post URN or ID to delete via the Posts API (idempotent, returns 204).")}).describe("Delete a LinkedIn post using the Posts API REST endpoint."),Ue=e.object({share_id:e.string().describe("The share ID of the LinkedIn share to delete.")}).describe("Delete a specific LinkedIn post (share) by its share_id."),ve=e.object({ugc_post_urn:e.string().describe("The UGC post URN (e.g. urn:li:ugcPost:12345) to delete.")}).describe("Delete a UGC post using the legacy v2/ugcPosts endpoint (idempotent)."),Ge=e.object({commented_on_urn:e.string().describe("URN of the object being commented on: a share, UGC post, or parent comment."),actor:g.describe("URN of the member or organization posting the comment, e.g. urn:li:person:... or urn:li:organization:...."),message:e.string().describe("The text of the comment (max 3000 characters).")}).describe("Create a first-level or nested comment on a LinkedIn share, UGC post, or comment."),Oe=e.object({entity_urn:e.string().describe("URN of the entity (share, post, or comment) whose reactions to list."),start:e.number().optional().describe("Pagination start index. Defaults to 0."),count:e.number().optional().describe("Number of reactions to return per page.")}).describe("Retrieve reactions (likes, celebrations, etc.) on a LinkedIn entity."),_e=e.object({image_urn:e.string().describe("The image URN (e.g. urn:li:image:C4D22...) whose details to retrieve.")}).describe("Retrieve details of a single LinkedIn image by its URN."),ze=e.object({owner:g.optional().describe("Owner URN. Returns images owned by this member/org."),urns:e.array(e.string()).optional().describe("Specific image URNs to fetch in a single batch request."),start:e.number().optional().describe("Pagination start index."),count:e.number().optional().describe("Number of images per page.")}).refine(n=>!!(n.owner||n.urns&&n.urns.length>0),{message:"getImages requires owner or a non-empty urns list \u2014 LinkedIn rejects /v2/images without a q finder."}).describe("Retrieve LinkedIn image metadata (download URLs, status, dimensions)."),Ne=e.object({owner:g.describe("Owner URN that will own the uploaded image, e.g. urn:li:person:... or urn:li:organization:....")}).describe("Initialize a LinkedIn image upload and return a presigned upload URL plus the image URN."),De=e.object({owner:g.describe("Owner URN for the media asset, e.g. urn:li:person:... or urn:li:organization:....")}).describe("Register a native LinkedIn image upload for feed shares and return a presigned upload URL plus the digital media asset URN."),xe=e.object({video_urn:e.string().optional().describe("A single video URN to retrieve."),owner:g.optional().describe("Owner URN. Returns videos owned by this account."),urns:e.array(e.string()).optional().describe("Specific video URNs to fetch in a batch."),start:e.number().optional().describe("Pagination start index."),count:e.number().optional().describe("Number of videos per page.")}).refine(n=>!!(n.video_urn||n.owner||n.urns&&n.urns.length>0),{message:"getVideos requires video_urn, owner, or a non-empty urns list \u2014 LinkedIn rejects /v2/videos without a q finder."}).describe("Retrieve LinkedIn video metadata (duration, dimensions, download URLs)."),je=e.object({role_assignee:g.optional().describe("Person URN whose organization roles to list. Defaults to the authenticated member."),role:e.array(e.enum(["ADMINISTRATOR","DIRECT_SPONSORED_CONTENT_POSTER","RECRUITING_POSTER","LEAD_GEN_FORMS_MANAGER","CONTENT_ADMIN","ANALYTICS_ROLE"])).optional().describe("Filter to specific organization roles."),state:e.enum(["APPROVED","PENDING","REVOKED"]).optional().describe("Filter to ACLs in a given state. Defaults to APPROVED."),start:e.number().int().min(0).optional().describe("Zero-based pagination offset into the role list."),count:e.number().int().min(1).optional().describe("Maximum number of roles to return per page.")}).describe("Retrieve organizations where the authenticated user has specific roles (ACLs)."),qe=e.object({organization_urn:g.describe("The organization URN (e.g. urn:li:organization:2414183) whose follower count to retrieve.")}).describe("Retrieve the follower count for a LinkedIn organization."),Fe=e.object({organization_urn:g.describe("The organization URN whose page statistics to retrieve."),time_integrated:e.object({start:e.number().optional(),end:e.number().optional()}).optional().describe("Optional time range for time-bound (aggregate) statistics."),start:e.number().optional().describe("Pagination start index."),count:e.number().optional().describe("Number of results per page.")}).describe("Retrieve page statistics (page views, custom button clicks) for a LinkedIn organization."),Me=e.object({organization_urn:g.describe("The organization URN whose share statistics to retrieve."),time_integrated:e.object({start:e.number().optional(),end:e.number().optional()}).optional().describe("Optional time range to filter statistics."),start:e.number().optional().describe("Pagination start index."),count:e.number().optional().describe("Number of results per page.")}).describe("Retrieve share statistics (impressions, clicks, likes, comments, shares) for an organization."),Be=e.object({}).describe("Retrieve available ad targeting facets from the LinkedIn Marketing API (locations, industries, job functions, etc.)."),Ve=e.object({target:e.record(e.string(),e.unknown()).describe("Targeting criteria to estimate audience size for, as a LinkedIn targeting object (e.g. { and: [ { or: [...] }] }).")}).describe("Retrieve audience size counts for specified targeting criteria."),He=e.object({query:e.string().describe("Typeahead search query for targeting entities."),type:e.string().optional().describe("Optional facet type to scope the search (e.g. locations, titles, industries).")}).describe("Search ad targeting entities (geographies, job titles, industries) via typeahead search."),s={GetMyInfo:Pe,GetPerson:Re,CreatePost:we,CreateArticleShare:Ce,GetPostContent:Ae,DeletePost:Te,DeleteSharePost:Ue,DeleteUgcPost:ve,CreateComment:Ge,ListReactions:Oe,GetImage:_e,GetImages:ze,InitializeImageUpload:Ne,RegisterImageUpload:De,GetVideos:xe,GetCompanyInfo:je,GetNetworkSize:qe,GetOrgPageStats:Fe,GetShareStats:Me,GetAdTargetingFacets:Be,GetAudienceCounts:Ve,SearchAdTargetingEntities:He},Ke=e.object({sub:e.string().optional(),id:e.string().optional(),name:e.string().nullable().optional(),given_name:e.string().nullable().optional(),family_name:e.string().nullable().optional(),picture:e.string().nullable().optional(),email:e.string().nullable().optional(),locale:e.string().nullable().optional(),vanityName:e.string().optional(),headline:e.string().optional()}).loose().describe("The authenticated LinkedIn member profile."),$e=e.object({id:e.string().describe("The member ID."),localizedFirstName:e.string().optional(),localizedLastName:e.string().optional(),localizedHeadline:e.string().optional(),vanityName:e.string().optional(),firstName:e.record(e.string(),e.unknown()).optional(),lastName:e.record(e.string(),e.unknown()).optional(),headline:e.record(e.string(),e.unknown()).optional(),profilePicture:e.object({"displayImage~":e.string().optional(),"displayImage~:playableStreams":e.array(e.record(e.string(),e.unknown())).optional()}).loose().optional()}).loose(),Qe=e.object({id:e.string().describe("The URN of the newly created post.")}).describe("Result of creating a LinkedIn post."),We=e.object({id:e.string().describe("The URN of the newly created UGC post."),activity:e.string().optional()}).describe("Result of creating an article/URL share."),Xe=e.object({id:e.string(),author:e.string().optional(),commentary:e.string().optional(),visibility:e.string().optional(),lifecycleState:e.string().optional(),createdAt:e.record(e.string(),e.unknown()).optional(),isReshareDisabledByAuthor:e.boolean().optional(),media:e.record(e.string(),e.unknown()).optional(),content:e.record(e.string(),e.unknown()).optional()}).loose().describe("Detailed content of a LinkedIn post."),P=e.object({success:e.boolean().describe("Whether the delete operation completed.")}).describe("Result of deleting a post."),Ye=e.object({id:e.string().optional().describe("The URN of the created comment."),message:e.string().optional().describe("The comment text."),object:e.string().optional().describe("The URN the comment was posted on."),lastModified:e.record(e.string(),e.unknown()).optional()}).loose().describe("Result of creating a comment."),Ze=e.object({actor:e.string().optional().describe("URN of the member who reacted."),type:e.string().optional().describe("Reaction type, e.g. LIKE, CELEBRATION."),created:e.record(e.string(),e.unknown()).optional()}).loose(),Je=e.object({elements:e.array(Ze).describe("The reactions on the entity."),paging:u}).loose().describe("Reactions on a LinkedIn entity."),Z=e.object({id:e.string().describe("The image URN."),owner:e.string().optional(),status:e.string().optional().describe("UPLOADING, AVAILABLE, WAITING_UPLOAD, etc."),downloadUrl:e.string().nullable().optional(),original:e.object({size:e.string().optional(),width:e.number().optional(),height:e.number().optional()}).loose().optional()}).loose(),et=Z,tt=e.object({elements:e.array(Z),paging:u}).loose(),nt=e.object({value:e.object({image:e.string().describe("The new image URN to use when attaching the image to a post."),uploadUrl:e.string().optional().describe("Presigned URL to PUT the image bytes to."),uploadUrlExpiresAt:e.number().optional().describe("Epoch millis when the upload URL expires.")}).loose()}).loose().describe("Result of initializing an image upload."),it=e.object({value:e.object({asset:e.string().describe("The digital media asset URN to reference in a post."),mediaArtifact:e.string().optional(),uploadMechanism:e.record(e.string(),e.unknown()).optional().describe("Contains the uploadUrl under com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest.")}).loose()}).loose().describe("Result of registering an image upload."),ot=e.object({id:e.string().describe("The video URN."),owner:e.string().optional(),status:e.string().optional().describe("UPLOADING, AVAILABLE, etc."),downloadUrl:e.string().nullable().optional(),durationMilliseconds:e.number().optional(),original:e.object({width:e.number().optional(),height:e.number().optional()}).loose().optional()}).loose(),rt=e.object({elements:e.array(ot),paging:u}).loose(),st=e.object({organization:e.string().optional().describe("Organization URN."),organizationRoleAssignee:e.string().optional(),role:e.string().optional().describe("The role held, e.g. ADMINISTRATOR."),state:e.string().optional()}).loose(),at=e.object({elements:e.array(st),paging:u}).loose(),dt=e.object({totalFollowerCount:e.number().optional().describe("Total followers of the organization."),organizationFollowerCount:e.number().optional(),elements:e.array(e.record(e.string(),e.unknown())).optional(),paging:u}).loose().describe("Follower count for a LinkedIn organization."),J=e.record(e.string(),e.unknown()),ct=e.object({elements:e.array(J).describe("Page statistics entries."),paging:u}).loose(),lt=e.object({elements:e.array(J).describe("Share statistics entries."),paging:u}).loose(),pt=e.object({facets:e.array(e.record(e.string(),e.unknown())).optional().describe("Available targeting facets."),elements:e.array(e.record(e.string(),e.unknown())).optional()}).loose(),gt=e.object({elements:e.array(e.record(e.string(),e.unknown())).optional().describe("Audience size entries for the given targeting criteria."),paging:u}).loose(),ut=e.object({elements:e.array(e.record(e.string(),e.unknown())).optional().describe("Matching targeting entities."),paging:u}).loose(),a={GetMyInfo:Ke,GetPerson:$e,CreatePost:Qe,CreateArticleShare:We,GetPostContent:Xe,DeletePost:P,DeleteSharePost:P,DeleteUgcPost:P,CreateComment:Ye,ListReactions:Je,GetImage:et,GetImages:tt,InitializeImageUpload:nt,RegisterImageUpload:it,GetVideos:rt,GetCompanyInfo:at,GetNetworkSize:dt,GetOrgPageStats:ct,GetShareStats:lt,GetAdTargetingFacets:pt,GetAudienceCounts:gt,SearchAdTargetingEntities:ut};var R={getMyInfo:Q,getPerson:W},m={create:F,createArticleShare:M,getContent:B,delete:V,deleteShare:H,deleteUgc:K},ee={create:G},te={list:X},f={get:O,list:_,initializeUpload:z,registerUpload:N},ne={list:Y},b={getCompanyInfo:D,getNetworkSize:x,getPageStats:j,getShareStats:q},E={getTargetingFacets:T,getAudienceCounts:U,searchTargetingEntities:v};import{ApiError as oe}from"corsair/http";function ie(n){if(n instanceof d||n instanceof oe)return n.status}var re={RATE_LIMIT_ERROR:{match:n=>{if(ie(n)===429)return!0;let t=n.message.toLowerCase();return t.includes("rate_limited")||t.includes("too many requests")||t.includes("429")},handler:async n=>{let t;return(n instanceof d&&n.retryAfter!==void 0||n instanceof oe&&n.retryAfter!==void 0)&&(t=n.retryAfter),{maxRetries:5,headersRetryAfterMs:t}}},AUTH_ERROR:{match:n=>{if(ie(n)===401)return!0;let t=n.message.toLowerCase();return t.includes("unauthorized")||t.includes("invalid_auth")},handler:async()=>({maxRetries:0})},DEFAULT:{match:()=>!0,handler:async()=>({maxRetries:0})}};import{z as l}from"zod";var se=l.object({id:l.string().describe("The LinkedIn member ID of the authenticated user."),sub:l.string().optional().describe("The OIDC subject identifier."),name:l.string().nullable().optional().describe("Display name of the member."),given_name:l.string().nullable().optional().describe("First name."),family_name:l.string().nullable().optional().describe("Last name."),picture:l.string().nullable().optional().describe("Profile picture URL."),email:l.string().nullable().optional().describe("Primary email address."),locale:l.string().nullable().optional().describe("Preferred locale."),headline:l.string().nullable().optional().describe("Profile headline."),vanityName:l.string().nullable().optional().describe("Public vanity name."),createdAt:l.coerce.date().nullable().optional(),updatedAt:l.coerce.date().nullable().optional()});var ae={version:"1.0.0",entities:{users:se}};var It={oauth_2:{integration:[]}},ft={profile:{getMyInfo:R.getMyInfo,getPerson:R.getPerson},posts:{create:m.create,createArticleShare:m.createArticleShare,getContent:m.getContent,delete:m.delete,deleteShare:m.deleteShare,deleteUgc:m.deleteUgc},comments:{create:ee.create},reactions:{list:te.list},images:{get:f.get,list:f.list,initializeUpload:f.initializeUpload,registerUpload:f.registerUpload},videos:{list:ne.list},organizations:{getCompanyInfo:b.getCompanyInfo,getNetworkSize:b.getNetworkSize,getPageStats:b.getPageStats,getShareStats:b.getShareStats},ads:{getTargetingFacets:E.getTargetingFacets,getAudienceCounts:E.getAudienceCounts,searchTargetingEntities:E.searchTargetingEntities}},bt={"profile.getMyInfo":{input:s.GetMyInfo,output:a.GetMyInfo},"profile.getPerson":{input:s.GetPerson,output:a.GetPerson},"posts.create":{input:s.CreatePost,output:a.CreatePost},"posts.createArticleShare":{input:s.CreateArticleShare,output:a.CreateArticleShare},"posts.getContent":{input:s.GetPostContent,output:a.GetPostContent},"posts.delete":{input:s.DeletePost,output:a.DeletePost},"posts.deleteShare":{input:s.DeleteSharePost,output:a.DeleteSharePost},"posts.deleteUgc":{input:s.DeleteUgcPost,output:a.DeleteUgcPost},"comments.create":{input:s.CreateComment,output:a.CreateComment},"reactions.list":{input:s.ListReactions,output:a.ListReactions},"images.get":{input:s.GetImage,output:a.GetImage},"images.list":{input:s.GetImages,output:a.GetImages},"images.initializeUpload":{input:s.InitializeImageUpload,output:a.InitializeImageUpload},"images.registerUpload":{input:s.RegisterImageUpload,output:a.RegisterImageUpload},"videos.list":{input:s.GetVideos,output:a.GetVideos},"organizations.getCompanyInfo":{input:s.GetCompanyInfo,output:a.GetCompanyInfo},"organizations.getNetworkSize":{input:s.GetNetworkSize,output:a.GetNetworkSize},"organizations.getPageStats":{input:s.GetOrgPageStats,output:a.GetOrgPageStats},"organizations.getShareStats":{input:s.GetShareStats,output:a.GetShareStats},"ads.getTargetingFacets":{input:s.GetAdTargetingFacets,output:a.GetAdTargetingFacets},"ads.getAudienceCounts":{input:s.GetAudienceCounts,output:a.GetAudienceCounts},"ads.searchTargetingEntities":{input:s.SearchAdTargetingEntities,output:a.SearchAdTargetingEntities}},kt={"profile.getMyInfo":{riskLevel:"read",description:"Fetch the authenticated LinkedIn member's profile."},"profile.getPerson":{riskLevel:"read",description:"Retrieve a LinkedIn member profile by person ID."},"posts.create":{riskLevel:"write",description:"Create a new LinkedIn post for a member or organization."},"posts.createArticleShare":{riskLevel:"write",description:"Create an article or URL share on LinkedIn."},"posts.getContent":{riskLevel:"read",description:"Retrieve detailed content of a specific LinkedIn post."},"posts.delete":{riskLevel:"destructive",irreversible:!0,description:"Delete a LinkedIn post via the Posts API."},"posts.deleteShare":{riskLevel:"destructive",irreversible:!0,description:"Delete a LinkedIn post (share) by its share_id."},"posts.deleteUgc":{riskLevel:"destructive",irreversible:!0,description:"Delete a UGC post via the legacy v2/ugcPosts endpoint."},"comments.create":{riskLevel:"write",description:"Create a comment on a LinkedIn share, UGC post, or comment."},"reactions.list":{riskLevel:"read",description:"List reactions on a LinkedIn entity."},"images.get":{riskLevel:"read",description:"Retrieve details of a single LinkedIn image by URN."},"images.list":{riskLevel:"read",description:"Retrieve LinkedIn image metadata."},"images.initializeUpload":{riskLevel:"write",description:"Initialize a LinkedIn image upload and return an upload URL."},"images.registerUpload":{riskLevel:"write",description:"Register a native image upload for feed shares."},"videos.list":{riskLevel:"read",description:"Retrieve LinkedIn video metadata."},"organizations.getCompanyInfo":{riskLevel:"read",description:"Retrieve organizations where the user has roles."},"organizations.getNetworkSize":{riskLevel:"read",description:"Retrieve the follower count for a LinkedIn organization."},"organizations.getPageStats":{riskLevel:"read",description:"Retrieve page statistics for a LinkedIn organization."},"organizations.getShareStats":{riskLevel:"read",description:"Retrieve share statistics for an organization."},"ads.getTargetingFacets":{riskLevel:"read",description:"Retrieve available LinkedIn ad targeting facets."},"ads.getAudienceCounts":{riskLevel:"read",description:"Retrieve audience size counts for targeting criteria."},"ads.searchTargetingEntities":{riskLevel:"read",description:"Search LinkedIn ad targeting entities via typeahead."}},yt="oauth_2";function tn(n={}){let t={...n,authType:n.authType??yt};return{id:"linkedin",schema:ae,options:t,authConfig:It,oauthConfig:{providerName:"LinkedIn",authUrl:"https://www.linkedin.com/oauth/v2/authorization",tokenUrl:"https://www.linkedin.com/oauth/v2/accessToken",tokenAuthMethod:"body",scopes:["openid","profile","email","r_basicprofile","r_member_social","w_member_social","r_organization_social","w_organization_social","rw_organization_admin","r_organization_admin","r_organization_relationships","r_ads","rw_ads","r_1st_connections_size"]},hooks:t.hooks,endpoints:ft,endpointSchemas:bt,endpointMeta:kt,errorHandlers:{...re,...t.errorHandlers},keyBuilder:async i=>{if(t.key)return t.key;if(i.authType!=="oauth_2")throw new mt("linkedin","oauth_2");return ht(i,{plugin:"linkedin",tokenUrl:"https://www.linkedin.com/oauth/v2/accessToken",tokenAuthMethod:"body"})}}}export{bt as LinkedInEndpointSchemas,ft as LinkedInEndpointsNested,tn as linkedin,It as linkedinAuthConfig};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@corsair-dev/linkedin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "LinkedIn plugin for Corsair",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"corsair": ">=0.1.
|
|
17
|
+
"corsair": ">=0.1.120",
|
|
18
18
|
"zod": "^4.1.13"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"tsup": "^8.0.1",
|
|
27
27
|
"typescript": "^5.9.3",
|
|
28
28
|
"zod": "^4.1.13",
|
|
29
|
-
"corsair": "0.1.
|
|
29
|
+
"corsair": "0.1.129"
|
|
30
30
|
},
|
|
31
31
|
"keywords": [
|
|
32
32
|
"corsair",
|
|
@@ -34,11 +34,17 @@
|
|
|
34
34
|
"plugin",
|
|
35
35
|
"marketing-api"
|
|
36
36
|
],
|
|
37
|
-
"author": "",
|
|
37
|
+
"author": "Corsair (https://corsair.dev)",
|
|
38
38
|
"license": "Apache-2.0",
|
|
39
39
|
"files": [
|
|
40
40
|
"dist"
|
|
41
41
|
],
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/corsairdev/corsair.git",
|
|
45
|
+
"directory": "packages/linkedin"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://docs.corsair.dev/plugins/linkedin",
|
|
42
48
|
"scripts": {
|
|
43
49
|
"build": "rm -rf dist && tsc --build --force && tsup",
|
|
44
50
|
"typecheck": "tsc --noEmit",
|