🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

@microfox/linkedin-share-sdk

Package Overview
Dependencies
Maintainers
2
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@microfox/linkedin-share-sdk

LinkedIn SDK for Microfox - A robust TypeScript SDK for LinkedIn Share API integration

1.1.0
latest
Source
npm
Version published
Maintainers
2
Created
Source

@microfox/linkedin-share-sdk

A robust TypeScript SDK for sharing content on LinkedIn with built-in Zod validation.

Features

  • 📘 Full TypeScript support with type definitions
  • 🛡️ Runtime validation with Zod schemas
  • 📱 Rich content sharing capabilities:
    • Text posts
    • Articles
    • Images
    • Videos
    • Documents
  • 🔒 Multiple visibility options (Public, Connections, Logged-in)
  • ⚠️ Comprehensive error handling with descriptive messages
  • 🎯 Simple, intuitive API

Installation

npm install @microfox/linkedin-share-sdk
# or
yarn add @microfox/linkedin-share-sdk
# or
pnpm add @microfox/linkedin-share-sdk

Usage

Basic Setup

import { LinkedinShareSdk } from '@microfox/linkedin-share-sdk';

const share = new LinkedinShareSdk('your_access_token');

Share Content

Simple Text Post

await share.post({
  text: 'Hello LinkedIn!',
  visibility: 'PUBLIC', // Default visibility
});

Share an Article

await share.post({
  text: 'Check out this article!',
  mediaCategory: 'ARTICLE',
  media: [
    {
      url: 'https://example.com/article',
      title: 'Amazing Article',
      description: 'Must-read content',
    },
  ],
});

Share an Image

await share.post({
  text: 'Check out this image!',
  mediaCategory: 'IMAGE',
  media: [
    {
      url: 'https://example.com/image.jpg',
      title: 'My Image',
      thumbnailUrl: 'https://example.com/thumbnail.jpg',
    },
  ],
});

Share with Custom Visibility

await share.post({
  text: 'For my connections only',
  visibility: 'CONNECTIONS',
});

Create a Draft Post

await share.post({
  text: 'Draft post',
  isDraft: true,
});

Validation and Error Handling

The SDK uses Zod for comprehensive validation at multiple levels:

  • Input Validation: All post options are validated before processing
  • Content Validation: The constructed share content is validated before sending to LinkedIn
  • Response Validation: LinkedIn's response is validated to ensure correct format

Handling Validation Errors

import { z } from 'zod';
import { LinkedinShareSdk } from '@microfox/linkedin-share-sdk';

const share = new LinkedinShareSdk('your_access_token');

try {
  await share.post({
    text: 'Hello LinkedIn!',
    mediaCategory: 'INVALID_CATEGORY', // This will trigger a validation error
  });
} catch (error) {
  if (error instanceof z.ZodError) {
    // Handle validation errors
    console.error('Validation failed:', error.errors);
    // error.errors will contain detailed information about what went wrong
    // [{
    //   code: 'invalid_enum_value',
    //   path: ['mediaCategory'],
    //   message: "Invalid enum value. Expected 'NONE' | 'ARTICLE' | 'IMAGE' | 'VIDEO' | 'DOCUMENT'"
    // }]
  } else {
    // Handle other errors (network, LinkedIn API, etc.)
    console.error('Share failed:', error.message);
  }
}

Available Schemas

The SDK exports its Zod schemas if you need to validate data before calling the API:

import {
  postOptionsSchema,
  mediaContentSchema,
  mediaCategorySchema,
  visibilitySchema,
} from '@microfox/linkedin-share-sdk';

// Validate post options
const validOptions = postOptionsSchema.parse({
  text: 'Hello',
  mediaCategory: 'IMAGE',
});

// Validate media content
const validMedia = mediaContentSchema.parse({
  url: 'https://example.com/image.jpg',
  title: 'My Image',
});

Types

import type {
  LinkedInPostOptions,
  LinkedInShareContent,
  LinkedInShareResponse,
  LinkedInMediaContent,
  LinkedInVisibility,
  MediaCategory,
} from '@microfox/linkedin-share-sdk';

Media Categories

type MediaCategory = 'NONE' | 'ARTICLE' | 'IMAGE' | 'VIDEO' | 'DOCUMENT';

Visibility Options

type LinkedInVisibility = 'PUBLIC' | 'CONNECTIONS' | 'LOGGED_IN';

Post Options

interface LinkedInPostOptions {
  text: string;
  visibility?: LinkedInVisibility;
  mediaCategory?: MediaCategory;
  media?: LinkedInMediaContent[];
  isDraft?: boolean;
}

Media Content

interface LinkedInMediaContent {
  url?: string;
  title?: string;
  description?: string;
  thumbnailUrl?: string;
}

License

MIT

Keywords

microfox

FAQs

Package last updated on 06 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts