Skip to content

API quick start ​

Part of Build an integration: shared APIs and infrastructure for adapter authors. For application usage, choose a library.

Create a catalog, select a saved profile and search its metadata. This complete example uses an in-memory SSH profile; it reads no native settings and opens no network connection.

Install ​

sh
npm install @jalsoedesign/portline-core

For the default TypeScript tab, also install tsx, typescript and @types/node as development dependencies. Set "type": "module" in package.json for TypeScript and JavaScript; the MJS and CommonJS extensions choose their module format explicitly. The example setup guide has copyable commands for every tab.

Create a catalog ​

Save the selected tab as profiles.ts, profiles.js, profiles.mjs or profiles.cjs.

ts
// profiles.ts
import {ProfileCatalog} from '@jalsoedesign/portline-core';

const source = {id: 'demo', application: 'demo'};
const catalog = new ProfileCatalog(source, [
    {
        id: 'demo',
        name: 'Demo',
        path: 'Demo',
        source,
        diagnostics: [],
        connections: [
            {
                id: 'ssh',
                kind: 'ssh',
                protocol: 'ssh',
                endpoint: {host: '127.0.0.1', port: 22, username: 'fixture'},
                authentication: [],
            },
        ],
    },
]);

const selected = catalog.get('Demo');
const connection = selected?.connections[0];

if (!selected || !connection) {
    throw new Error('The demo profile must contain a connection');
}

const matches = catalog.search('127.0.0.1', {fields: 'all'});

console.log('Profiles: ' + catalog.list().length);
console.log('Selected: ' + selected.path);
console.log('Host: ' + connection.endpoint.host);
console.log('Matches: ' + matches.length);
console.log('Metadata only: no settings read and no connection opened.');
js
// profiles.js
import {ProfileCatalog} from '@jalsoedesign/portline-core';

const source = {id: 'demo', application: 'demo'};
const catalog = new ProfileCatalog(source, [
    {
        id: 'demo',
        name: 'Demo',
        path: 'Demo',
        source,
        diagnostics: [],
        connections: [
            {
                id: 'ssh',
                kind: 'ssh',
                protocol: 'ssh',
                endpoint: {host: '127.0.0.1', port: 22, username: 'fixture'},
                authentication: [],
            },
        ],
    },
]);

const selected = catalog.get('Demo');
const connection = selected?.connections[0];

if (!selected || !connection) {
    throw new Error('The demo profile must contain a connection');
}

const matches = catalog.search('127.0.0.1', {fields: 'all'});

console.log('Profiles: ' + catalog.list().length);
console.log('Selected: ' + selected.path);
console.log('Host: ' + connection.endpoint.host);
console.log('Matches: ' + matches.length);
console.log('Metadata only: no settings read and no connection opened.');
js
// profiles.mjs
import {ProfileCatalog} from '@jalsoedesign/portline-core';

const source = {id: 'demo', application: 'demo'};
const catalog = new ProfileCatalog(source, [
    {
        id: 'demo',
        name: 'Demo',
        path: 'Demo',
        source,
        diagnostics: [],
        connections: [
            {
                id: 'ssh',
                kind: 'ssh',
                protocol: 'ssh',
                endpoint: {host: '127.0.0.1', port: 22, username: 'fixture'},
                authentication: [],
            },
        ],
    },
]);

const selected = catalog.get('Demo');
const connection = selected?.connections[0];

if (!selected || !connection) {
    throw new Error('The demo profile must contain a connection');
}

const matches = catalog.search('127.0.0.1', {fields: 'all'});

console.log('Profiles: ' + catalog.list().length);
console.log('Selected: ' + selected.path);
console.log('Host: ' + connection.endpoint.host);
console.log('Matches: ' + matches.length);
console.log('Metadata only: no settings read and no connection opened.');
js
// profiles.cjs
const {ProfileCatalog} = require('@jalsoedesign/portline-core');

async function main() {
    const source = {id: 'demo', application: 'demo'};
    const catalog = new ProfileCatalog(source, [
        {
            id: 'demo',
            name: 'Demo',
            path: 'Demo',
            source,
            diagnostics: [],
            connections: [
                {
                    id: 'ssh',
                    kind: 'ssh',
                    protocol: 'ssh',
                    endpoint: {host: '127.0.0.1', port: 22, username: 'fixture'},
                    authentication: [],
                },
            ],
        },
    ]);

    const selected = catalog.get('Demo');
    const connection = selected?.connections[0];

    if (!selected || !connection) {
        throw new Error('The demo profile must contain a connection');
    }

    const matches = catalog.search('127.0.0.1', {fields: 'all'});

    console.log('Profiles: ' + catalog.list().length);
    console.log('Selected: ' + selected.path);
    console.log('Host: ' + connection.endpoint.host);
    console.log('Matches: ' + matches.length);
    console.log('Metadata only: no settings read and no connection opened.');
}

main().catch(error => {
    console.error(error);
    process.exitCode = 1;
});

Run it ​

sh
npx tsx profiles.ts
sh
node profiles.js
sh
node profiles.mjs
sh
node profiles.cjs

Output ​

text
Profiles: 1
Selected: Demo
Host: 127.0.0.1
Matches: 1
Metadata only: no settings read and no connection opened.

Download: profiles.ts · profiles.js · profiles.mjs · profiles.cjs

Use native saved connections ​

Replace the in-memory catalog with an application adapter. Adapters expose the same list, get and search source contract while interpreting their own native settings.

Continue with catalog queries, explicit credential resolution or a safe sync preview.