Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/linkedin

src/types.ts

144 lines · 3.0 KB · TypeScript
export type JsonRecord = Record<string, unknown>

export type QueryValue = string | number | boolean | null | undefined
export type QueryInput = Record<string, QueryValue | QueryValue[]>

export type LinkedInUserInfo = JsonRecord & {
	sub: string
	name?: string
	given_name?: string
	family_name?: string
	picture?: string
	locale?: string
	email?: string
	email_verified?: boolean
}

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

export type LinkedInRequestInput = {
	path: string
	method?: string
	query?: QueryInput
	headers?: Record<string, string>
	body?: unknown
	dryRun?: boolean
	confirm?: boolean
}

export type CreateTextPostInput = {
	text: string
	author?: string
	visibility?: LinkedInVisibility
	isReshareDisabledByAuthor?: boolean
	dryRun?: boolean
	confirm?: boolean
}

export type CreateArticlePostInput = CreateTextPostInput & {
	url: string
	title: string
	description: string
	thumbnail?: string
	thumbnailUrl?: string
}

export type DeletePostInput = {
	postUrn: string
	dryRun?: boolean
	confirm?: boolean
}

export type RegisterImageUploadInput = {
	owner?: string
	dryRun?: boolean
	confirm?: boolean
}

export type CreateImagePostInput = CreateTextPostInput & {
	asset?: string
	imageUrn?: string
	title?: string
	description?: string
	altText?: string
}

export type VideoUploadInstruction = JsonRecord & {
	uploadUrl: string
	firstByte: number
	lastByte: number
}

export type RegisterVideoUploadInput = {
	owner?: string
	fileSizeBytes: number
	uploadCaptions?: boolean
	uploadThumbnail?: boolean
	linkbackContext?: string
	templateName?: string
	dryRun?: boolean
	confirm?: boolean
}

export type UploadVideoPartInput = {
	uploadUrl: string
	bytes?: unknown
	bytesBase64?: string
	uploadFromUrl?: string
	contentType?: string
	dryRun?: boolean
	confirm?: boolean
}

export type FinalizeVideoUploadInput = {
	video: string
	uploadToken?: string
	uploadedPartIds: string[]
	dryRun?: boolean
	confirm?: boolean
}

export type CreateVideoPostInput = CreateTextPostInput & {
	videoUrn?: string
	uploadFromBytes?: unknown
	uploadFromUrl?: string
	fileSizeBytes?: number
	uploadCaptions?: boolean
	uploadThumbnail?: boolean
	title?: string
}

export type CreatePostInput = {
	commentary?: string
	text?: string
	author?: string
	visibility?: LinkedInVisibility
	content?: JsonRecord
	distribution?: JsonRecord
	isReshareDisabledByAuthor?: boolean
	dryRun?: boolean
	confirm?: boolean
}

export type LinkedInRequestResult = {
	ok: boolean
	status: number
	statusText: string
	headers: Record<string, string>
	body: unknown
}

export function requireRecord(value: unknown, utilityName: string): JsonRecord {
	if (value && typeof value === 'object' && !Array.isArray(value)) {
		return value as JsonRecord
	}
	throw new Error(utilityName + ' requires an object params value.')
}

export function requireStringField(record: JsonRecord, key: string, utilityName: string): string {
	const value = record[key]
	if (typeof value !== 'string' || value.length === 0) {
		throw new Error(utilityName + ' requires params.' + key + '.')
	}
	return value
}