@corsair-dev/linkedin 0.1.3 → 0.1.4

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/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # @corsair-dev/linkedin
2
2
 
3
3
  LinkedIn plugin for Corsair. Covers member profile, posts and shares,
4
- comments, reactions, media (images and videos), organization pages, and
5
- the Ads targeting/audience APIs.
4
+ comments, reactions, media (images and videos), organization pages and
5
+ statistics, and the Advertising API (targeting, audience counts, ad
6
+ accounts, campaigns and reporting).
6
7
 
7
8
  ## Authentication
8
9
 
@@ -11,35 +12,65 @@ The plugin uses **OAuth 2.0** (`oauth_2`) against LinkedIn.
11
12
  1. Create an app at the
12
13
  [LinkedIn Developer Portal](https://developer.linkedin.com/) and add
13
14
  your Corsair callback URL as an authorized redirect URL.
14
- 2. Request the products your use case needs (e.g. _Sign In with
15
- LinkedIn_, _Share on LinkedIn_, _Community Management API_,
16
- _Advertising API_). Scopes are only grantable once the matching
17
- product is approved for the app.
18
- 3. Supply the client ID and secret to Corsair. The OAuth flow requests
19
- these scopes: `openid`, `profile`, `email`, `r_basicprofile`,
20
- `r_member_social`, `w_member_social`, `r_organization_social`,
21
- `w_organization_social`, `rw_organization_admin`,
22
- `r_organization_admin`, `r_organization_relationships`, `r_ads`,
23
- `rw_ads`, `r_1st_connections_size`.
15
+ 2. Add the products your use case needs. Scopes are only grantable once
16
+ the matching product is approved for the app, and LinkedIn rejects the
17
+ whole sign-in if any requested scope is missing a product.
18
+ - _Sign In with LinkedIn using OpenID Connect_: `openid`, `profile`, `email`
19
+ - _Share on LinkedIn_: `w_member_social`
20
+ - _Advertising API_: `r_basicprofile`, `r_organization_social`,
21
+ `w_organization_social`, `r_organization_admin`,
22
+ `rw_organization_admin`, `r_ads`, `rw_ads`, `r_ads_reporting`
23
+ 3. Supply the client ID and secret to Corsair. By default the plugin asks
24
+ for the four self-serve scopes (`LINKEDIN_SELF_SERVE_SCOPES`), so a new
25
+ app signs in without any LinkedIn review. Once your app has the
26
+ Advertising API, ask for its scopes too:
27
+
28
+ ```ts
29
+ import { linkedin, LINKEDIN_ADVERTISING_SCOPES } from '@corsair-dev/linkedin';
30
+
31
+ linkedin({ scopes: LINKEDIN_ADVERTISING_SCOPES });
32
+ ```
33
+
34
+ Neither preset asks for `r_member_social` (closed to new apps) or
35
+ `r_organization_relationships` (no longer offered), so with the presets
36
+ reading a member's own posts is not available; organization posts are. An
37
+ app LinkedIn has already approved for `r_member_social` can add it to
38
+ `scopes` itself.
24
39
 
25
40
  Access tokens are refreshed proactively before expiry, rotated refresh
26
41
  tokens are persisted, and requests are retried once on a 401 with a
27
- force-refreshed token.
42
+ force-refreshed token. LinkedIn only issues refresh tokens to approved
43
+ partner apps; without one, the member signs in again when the 60-day access
44
+ token expires.
28
45
 
29
46
  ## Endpoints
30
47
 
31
- 22 operations across these domains:
48
+ 28 operations across these domains:
49
+
50
+ | Domain | Operations | Product / scope |
51
+ | --------------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------- |
52
+ | `profile` | `getMyInfo`, `getPerson` | OpenID Connect; `r_basicprofile` for `getPerson` |
53
+ | `posts` | `create`, `createArticleShare`, `getContent`, `list`, `delete`, `deleteShare`, `deleteUgc` | `w_member_social` / `w_organization_social`; reads `r_organization_social` |
54
+ | `comments` | `create`, `list` | same as posts per the Posts API (the Comments reference lists the Community Management `*_feed` scopes; unconfirmed which LinkedIn enforces) |
55
+ | `reactions` | `list` | `r_organization_social` |
56
+ | `images` | `initializeUpload`, `registerUpload` | `w_member_social` for the member's own images; `w_organization_social` or `rw_ads` for an organization or ad account |
57
+ | `images` | `get`, `list` | `w_organization_social` or `rw_ads` |
58
+ | `videos` | `list` | `w_organization_social`, `r_ads` or `rw_ads` |
59
+ | `organizations` | `getCompanyInfo`, `getNetworkSize`, `getFollowerStats`, `getPageStats`, `getShareStats` | `rw_organization_admin` (`r_organization_admin` for `getCompanyInfo`) |
60
+ | `ads` | `getTargetingFacets`, `getAudienceCounts`, `searchTargetingEntities`, `listAccounts`, `listCampaigns`, `getAnalytics` | Advertising API; `r_ads`; `r_ads_reporting` for `getAnalytics` |
61
+
62
+ Older operations now on current endpoints, with the same names:
32
63
 
33
- | Domain | Operations |
34
- | --------------- | ------------------------------------------------------------------------------------------------------ |
35
- | `profile` | `getMyInfo`, `getPerson` |
36
- | `posts` | `createPost`, `createArticleShare`, `getPostContent`, `deletePost`, `deleteSharePost`, `deleteUgcPost` |
37
- | `comments` | `createComment` |
38
- | `reactions` | `listReactions` |
39
- | `images` | `initializeImageUpload`, `registerImageUpload`, `getImage`, `getImages` |
40
- | `videos` | `getVideos` |
41
- | `organizations` | `getCompanyInfo`, `getNetworkSize`, `getOrgPageStats`, `getShareStats` |
42
- | `ads` | `getAdTargetingFacets`, `getAudienceCounts`, `searchAdTargetingEntities` |
64
+ - `posts.createArticleShare`, `posts.deleteShare`, `posts.deleteUgc` use the
65
+ Posts API (`/rest/posts`) instead of `/v2/ugcPosts` and `/v2/shares`.
66
+ `createArticleShare` now needs `article_title`, and `article_thumbnail`
67
+ must be an image URN: LinkedIn no longer fetches article previews.
68
+ - `images.registerUpload` calls the Images API `initializeUpload` action,
69
+ which LinkedIn says replaces the Assets API; it returns `value.image` and
70
+ `value.uploadUrl`.
71
+ - `organizations.getNetworkSize` reads the follower total from
72
+ `networkSizes`, since follower statistics no longer include it. The
73
+ follower breakdown is in `organizations.getFollowerStats`.
43
74
 
44
75
  ## Webhooks
45
76
 
@@ -48,17 +79,21 @@ plugin does not register any webhook handlers.
48
79
 
49
80
  ## Provider quirks
50
81
 
51
- - LinkedIn has two API surfaces: the legacy `/v2` endpoints and the
52
- versioned `/rest` endpoints. The client sends
53
- `X-Restli-Protocol-Version: 2.0.0` everywhere and a
54
- `LinkedIn-Version` header on versioned REST calls.
55
- - Entities are addressed by URNs (`urn:li:person:...`,
56
- `urn:li:share:...`, `urn:li:organization:...`); URNs inside request
57
- paths must be URL-encoded, which the endpoints handle internally.
58
- - Comment creation requires an `actor` URN and a `message` object (not
59
- a plain string) per the Social Actions API.
60
- - Media uploads are two-step: initialize/register the upload to get an
61
- upload URL, then upload the binary to that URL.
62
- - Most organization and ads endpoints additionally require the app to be
63
- granted the corresponding LinkedIn products; without them LinkedIn
64
- returns 403 regardless of the OAuth scopes requested.
82
+ - Every call except `/v2/userinfo` (OpenID Connect) and `/v2/people` goes
83
+ to the versioned `/rest` APIs with `LinkedIn-Version: 202611` and
84
+ `X-Restli-Protocol-Version: 2.0.0`. LinkedIn supports each version for
85
+ about a year, so bump `LINKEDIN_API_VERSION` in `client.ts` before
86
+ November 2027.
87
+ - Query values use Rest.li 2.0 syntax: URNs are percent-encoded, while
88
+ structure stays as written, e.g.
89
+ `timeIntervals=(timeRange:(start:1,end:2),timeGranularityType:DAY)` or
90
+ `ids=List(urn%3Ali%3Aimage%3Aa,urn%3Ali%3Aimage%3Ab)`. `restli.ts` builds
91
+ these.
92
+ - Creating a post returns 201 with no body; the post URN is in the
93
+ `x-restli-id` header.
94
+ - Ad accounts and campaigns page with `pageToken` / `metadata.nextPageToken`;
95
+ the other list endpoints use `start` / `count`.
96
+ - Media uploads are two-step: initialize the upload to get an upload URL
97
+ and the image URN, then PUT the bytes to that URL.
98
+ - Most organization and ads endpoints also need the member to hold the
99
+ right page or ad account role; without it LinkedIn returns 403.
package/dist/client.d.ts CHANGED
@@ -1,13 +1,17 @@
1
+ import type { RestliQuery } from './restli';
1
2
  export declare class LinkedInAPIError extends Error {
2
3
  readonly status?: number | undefined;
3
4
  readonly code?: string | undefined;
4
5
  readonly retryAfter?: number | undefined;
5
6
  constructor(message: string, status?: number | undefined, code?: string | undefined, retryAfter?: number | undefined);
6
7
  }
8
+ export declare const LINKEDIN_API_VERSION = "202611";
7
9
  export type LinkedInRequestOptions = {
8
10
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
9
11
  body?: Record<string, unknown>;
10
- query?: Record<string, string | number | boolean | ReadonlyArray<string> | undefined>;
12
+ query?: RestliQuery;
13
+ headers?: Record<string, string>;
14
+ responseHeader?: string;
11
15
  };
12
16
  export declare function makeLinkedInRequest<T>(endpoint: string, accessToken: string, options?: LinkedInRequestOptions): Promise<T>;
13
17
  export type LinkedInRequestContext = {
@@ -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;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,OA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ClC,OAAO,CAAC,CAAC,CAAC,CAUZ"}
@@ -2,4 +2,7 @@ import type { LinkedInEndpoints } from '../index';
2
2
  export declare const getAdTargetingFacets: LinkedInEndpoints['GetAdTargetingFacets'];
3
3
  export declare const getAudienceCounts: LinkedInEndpoints['GetAudienceCounts'];
4
4
  export declare const searchAdTargetingEntities: LinkedInEndpoints['SearchAdTargetingEntities'];
5
+ export declare const listAdAccounts: LinkedInEndpoints['ListAdAccounts'];
6
+ export declare const listAdCampaigns: LinkedInEndpoints['ListAdCampaigns'];
7
+ export declare const getAdAnalytics: LinkedInEndpoints['GetAdAnalytics'];
5
8
  //# sourceMappingURL=ads.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ads.d.ts","sourceRoot":"","sources":["../../endpoints/ads.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAKlD,eAAO,MAAM,oBAAoB,EAAE,iBAAiB,CAAC,sBAAsB,CAazE,CAAC;AAEH,eAAO,MAAM,iBAAiB,EAAE,iBAAiB,CAAC,mBAAmB,CAkBpE,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,iBAAiB,CAAC,2BAA2B,CAqBnF,CAAC"}
1
+ {"version":3,"file":"ads.d.ts","sourceRoot":"","sources":["../../endpoints/ads.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAuClD,eAAO,MAAM,oBAAoB,EAAE,iBAAiB,CAAC,sBAAsB,CAazE,CAAC;AAEH,eAAO,MAAM,iBAAiB,EAAE,iBAAiB,CAAC,mBAAmB,CAuBpE,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,iBAAiB,CAAC,2BAA2B,CAwBnF,CAAC;AAEH,eAAO,MAAM,cAAc,EAAE,iBAAiB,CAAC,gBAAgB,CA0B9D,CAAC;AAaF,eAAO,MAAM,eAAe,EAAE,iBAAiB,CAAC,iBAAiB,CAoChE,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,iBAAiB,CAAC,gBAAgB,CA2C9D,CAAC"}
@@ -1,3 +1,4 @@
1
1
  import type { LinkedInEndpoints } from '../index';
2
2
  export declare const createComment: LinkedInEndpoints['CreateComment'];
3
+ export declare const listComments: LinkedInEndpoints['ListComments'];
3
4
  //# sourceMappingURL=comments.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../../endpoints/comments.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGlD,eAAO,MAAM,aAAa,EAAE,iBAAiB,CAAC,eAAe,CA0B5D,CAAC"}
1
+ {"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../../endpoints/comments.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAQlD,eAAO,MAAM,aAAa,EAAE,iBAAiB,CAAC,eAAe,CAiC5D,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,iBAAiB,CAAC,cAAc,CAkB1D,CAAC"}
@@ -1,4 +1,24 @@
1
1
  import type { LinkedInEndpoints } from '../index';
2
+ import type { RestliQuery } from '../restli';
3
+ /** LinkedIn's BATCH_GET response: results, statuses and errors keyed by URN. */
4
+ export type BatchGetResponse<T> = {
5
+ results?: Record<string, T>;
6
+ statuses?: Record<string, number>;
7
+ errors?: Record<string, Record<string, unknown>>;
8
+ };
9
+ /**
10
+ * Lists the entities a BATCH_GET found, in the order they were asked for,
11
+ * next to LinkedIn's own results/statuses/errors maps.
12
+ */
13
+ export declare function withBatchElements<T>(urns: ReadonlyArray<string>, response: BatchGetResponse<T>): BatchGetResponse<T> & {
14
+ elements: T[];
15
+ };
16
+ /** Query for the media-library finder by ad account (images and videos). */
17
+ export declare function associatedAccountQuery(input: {
18
+ associated_account?: string;
19
+ start?: number;
20
+ count?: number;
21
+ }): RestliQuery;
2
22
  export declare const getImage: LinkedInEndpoints['GetImage'];
3
23
  export declare const getImages: LinkedInEndpoints['GetImages'];
4
24
  export declare const initializeImageUpload: LinkedInEndpoints['InitializeImageUpload'];
@@ -1 +1 @@
1
- {"version":3,"file":"images.d.ts","sourceRoot":"","sources":["../../endpoints/images.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGlD,eAAO,MAAM,QAAQ,EAAE,iBAAiB,CAAC,UAAU,CAclD,CAAC;AAOF,eAAO,MAAM,SAAS,EAAE,iBAAiB,CAAC,WAAW,CA+BpD,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,iBAAiB,CAAC,uBAAuB,CAkB3E,CAAC;AAEH,eAAO,MAAM,mBAAmB,EAAE,iBAAiB,CAAC,qBAAqB,CA4BvE,CAAC"}
1
+ {"version":3,"file":"images.d.ts","sourceRoot":"","sources":["../../endpoints/images.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAI7C,gFAAgF;AAChF,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACjD,CAAC;AAEF;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAClC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,EAC3B,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAC3B,gBAAgB,CAAC,CAAC,CAAC,GAAG;IAAE,QAAQ,EAAE,CAAC,EAAE,CAAA;CAAE,CAM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