Skip to main content

Class: OpenAlexPlugin

Defined in: src/plugins/builtin/openalex.ts:513

OpenAlex metadata enrichment plugin.

Remarks

Provides scholarly metadata lookup from OpenAlex's 250M+ works database. Used for preprint enrichment and author verification.

Example

const plugin = new OpenAlexPlugin();
await manager.loadBuiltinPlugin(plugin);

// Look up work by DOI
const work = await plugin.getWorkByDoi('10.1234/example');

// Get author by ORCID (for claiming verification)
const author = await plugin.getAuthorByOrcid('0000-0001-2345-6789');

Extends

Constructors

new OpenAlexPlugin()

new OpenAlexPlugin(): OpenAlexPlugin

Returns

OpenAlexPlugin

Inherited from

BasePlugin.constructor

Properties

cache

protected cache: ICacheProvider

Defined in: src/plugins/builtin/base-plugin.ts:88

Cache provider (available after initialization).

Inherited from

BasePlugin.cache


context

protected context: IPluginContext

Defined in: src/plugins/builtin/base-plugin.ts:78

Plugin context (available after initialization).

Inherited from

BasePlugin.context


id

readonly id: "pub.chive.plugin.openalex" = 'pub.chive.plugin.openalex'

Defined in: src/plugins/builtin/openalex.ts:517

Plugin ID.

Overrides

BasePlugin.id


logger

protected logger: ILogger

Defined in: src/plugins/builtin/base-plugin.ts:83

Logger instance (available after initialization).

Inherited from

BasePlugin.logger


manifest

readonly manifest: IPluginManifest

Defined in: src/plugins/builtin/openalex.ts:522

Plugin manifest.

Overrides

BasePlugin.manifest


metrics

protected metrics: IMetrics

Defined in: src/plugins/builtin/base-plugin.ts:93

Metrics provider (available after initialization).

Inherited from

BasePlugin.metrics

Methods

autocompleteAuthors()

autocompleteAuthors(query, options?): Promise<readonly object[]>

Defined in: src/plugins/builtin/openalex.ts:842

Autocompletes author names (fast endpoint).

Parameters

query

string

Name query

options?

Autocomplete options

limit

number

Returns

Promise<readonly object[]>

Matching authors with basic info

Remarks

Uses OpenAlex's dedicated autocomplete endpoint which is optimized for low latency (~200ms).


classifyText()

classifyText(title, abstract?): Promise<TextClassificationResult>

Defined in: src/plugins/builtin/openalex.ts:1029

Classifies text into topics, keywords, and concepts.

Parameters

title

string

Title text (required)

abstract?

string

Abstract text (optional, improves classification)

Returns

Promise<TextClassificationResult>

Classification results with topics, keywords, and concepts

Remarks

Uses the OpenAlex /text endpoint to classify arbitrary text (title + abstract) into OpenAlex topics, keywords, and concepts. This is useful for preprints that don't yet have a DOI in OpenAlex's database.

Rate Limits:

  • 1 request per second
  • 1,000 requests per day
  • Text must be 20-2000 characters

Example

const classification = await plugin.classifyText(
'Attention Is All You Need',
'The dominant sequence transduction models are based on complex...'
);

console.log('Primary topic:', classification.primaryTopic?.displayName);
console.log('Keywords:', classification.keywords.map(k => k.displayName).join(', '));

See

OpenAlex /text Endpoint


getAuthor()

getAuthor(id): Promise<null | OpenAlexAuthor>

Defined in: src/plugins/builtin/openalex.ts:781

Gets author by OpenAlex ID.

Parameters

id

string

OpenAlex author ID (A123456789)

Returns

Promise<null | OpenAlexAuthor>

Author profile or null


getAuthorByOrcid()

getAuthorByOrcid(orcid): Promise<null | OpenAlexAuthor>

Defined in: src/plugins/builtin/openalex.ts:720

Gets author by ORCID.

Parameters

orcid

string

ORCID iD

Returns

Promise<null | OpenAlexAuthor>

Author profile or null

Remarks

Used for claiming verification - OpenAlex author profiles linked to ORCID provide high-confidence identity verification.


getConfig()

protected getConfig<T>(key): undefined | T

Defined in: src/plugins/builtin/base-plugin.ts:226

Gets a configuration value with type safety.

Type Parameters

T

Parameters

key

string

Configuration key

Returns

undefined | T

Configuration value or undefined

Example

const apiKey = this.getConfig<string>('apiKey');

Inherited from

BasePlugin.getConfig


getRelatedWorks()

getRelatedWorks(workId): Promise<readonly string[]>

Defined in: src/plugins/builtin/openalex.ts:1133

Gets related works for a paper (pre-computed by OpenAlex).

Parameters

workId

string

OpenAlex work ID (e.g., "W2741809807")

Returns

Promise<readonly string[]>

Array of related work IDs

Remarks

OpenAlex pre-computes related works based on concept overlap and other signals. Returns up to 10 related work IDs.

Example

const relatedIds = await plugin.getRelatedWorks('W2741809807');
// Returns: ['W2123456789', 'W9876543210', ...]

// Fetch full metadata for related works
const relatedWorks = await plugin.getWorksBatch(relatedIds);

getRequiredConfig()

protected getRequiredConfig<T>(key): T

Defined in: src/plugins/builtin/base-plugin.ts:242

Gets a required configuration value.

Type Parameters

T

Parameters

key

string

Configuration key

Returns

T

Configuration value

Throws

Error if key not found

Example

const apiKey = this.getRequiredConfig<string>('apiKey');

Inherited from

BasePlugin.getRequiredConfig


getState()

getState(): PluginState

Defined in: src/plugins/builtin/base-plugin.ts:162

Gets current plugin state.

Returns

PluginState

Current lifecycle state

Inherited from

BasePlugin.getState


getWork()

getWork(id): Promise<null | OpenAlexWork>

Defined in: src/plugins/builtin/openalex.ts:599

Gets work by OpenAlex ID.

Parameters

id

string

OpenAlex work ID (W123456789)

Returns

Promise<null | OpenAlexWork>

Work metadata or null


getWorkByDoi()

getWorkByDoi(doi): Promise<null | OpenAlexWork>

Defined in: src/plugins/builtin/openalex.ts:655

Gets work by DOI.

Parameters

doi

string

DOI string

Returns

Promise<null | OpenAlexWork>

Work metadata or null


getWorksBatch()

getWorksBatch(workIds): Promise<readonly OpenAlexWork[]>

Defined in: src/plugins/builtin/openalex.ts:1190

Batch fetches multiple works efficiently.

Parameters

workIds

readonly string[]

Array of OpenAlex work IDs (max 50)

Returns

Promise<readonly OpenAlexWork[]>

Array of work metadata

Remarks

Uses OpenAlex's filter syntax to fetch up to 50 works in a single request. More efficient than individual getWork() calls.

Example

const works = await plugin.getWorksBatch([
'W2741809807',
'W2123456789',
'W9876543210',
]);

initialize()

initialize(context): Promise<void>

Defined in: src/plugins/builtin/base-plugin.ts:111

Initializes the plugin.

Parameters

context

IPluginContext

Plugin context with injected dependencies

Returns

Promise<void>

Remarks

Sets up context and calls onInitialize(). Subclasses should override onInitialize() instead of this method.

Inherited from

BasePlugin.initialize


onInitialize()

protected onInitialize(): Promise<void>

Defined in: src/plugins/builtin/openalex.ts:568

Initializes the plugin.

Returns

Promise<void>

Overrides

BasePlugin.onInitialize


onShutdown()

protected onShutdown(): Promise<void>

Defined in: src/plugins/builtin/base-plugin.ts:211

Override in subclass for shutdown logic.

Returns

Promise<void>

Remarks

Called during shutdown(). Use this to:

  • Save state
  • Close connections
  • Clean up resources

Default implementation does nothing.

Example

protected async onShutdown(): Promise<void> {
await this.saveState();
this.connection?.close();
}

Inherited from

BasePlugin.onShutdown


recordCounter()

protected recordCounter(name, labels?, value?): void

Defined in: src/plugins/builtin/base-plugin.ts:257

Records a counter metric.

Parameters

name

string

Metric name

labels?

Record<string, string>

Optional labels

value?

number

Optional increment value (default 1)

Returns

void

Inherited from

BasePlugin.recordCounter


recordGauge()

protected recordGauge(name, value, labels?): void

Defined in: src/plugins/builtin/base-plugin.ts:268

Records a gauge metric.

Parameters

name

string

Metric name

value

number

Gauge value

labels?

Record<string, string>

Optional labels

Returns

void

Inherited from

BasePlugin.recordGauge


searchWorks()

searchWorks(query, options?): Promise<readonly OpenAlexWork[]>

Defined in: src/plugins/builtin/openalex.ts:918

Searches for works.

Parameters

query

string

Search query

options?

Search options

filter

string

limit

number

Returns

Promise<readonly OpenAlexWork[]>

Matching works


shutdown()

shutdown(): Promise<void>

Defined in: src/plugins/builtin/base-plugin.ts:142

Shuts down the plugin.

Returns

Promise<void>

Remarks

Calls onShutdown() and updates state. Subclasses should override onShutdown() instead of this method.

Inherited from

BasePlugin.shutdown


startTimer()

protected startTimer(name, labels?): () => void

Defined in: src/plugins/builtin/base-plugin.ts:286

Starts a timer for histogram metrics.

Parameters

name

string

Metric name

labels?

Record<string, string>

Optional labels

Returns

Function

Function to call when operation completes

Returns

void

Example

const endTimer = this.startTimer('api_request');
await this.fetchData();
endTimer(); // Records duration

Inherited from

BasePlugin.startTimer