0.4.0 • Published 2 years ago

wikitree-js v0.4.0

Weekly downloads
-
License
Apache 2.0
Repository
github
Last release
2 years ago

npm Node.js CI

wikitree-js

JavaScript library to access the WikiTree API for Node.js and Web environments.

Setup

Add wikitree-js package to your project:

npm install wikitree-js

Import package:

import {getAncestors} from 'wikitree-js';

Usage

getPerson

API documentation

Example 1

Async/await:

const response = await getPerson('Skłodowska-2');

Promise:

const responsePromise = getPerson('Skłodowska-2')

responsePromise.then(response => {
  // ...
});

Live demo:

Example 2

Async/await:

const response = await getPerson(
  'Skłodowska-2',
  {
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
  }
);

Promise:

const responsePromise = getPerson(
  'Skłodowska-2',
  {
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
  }
);

responsePromise.then(response => {
  // ...
});

Live demo:

getAncestors

API documentation

Example 1

Async/await:

const response = await getAncestors('Skłodowska-2');

Promise:

const responsePromise = getAncestors('Skłodowska-2')

responsePromise.then(response => {
  // ...
});

Live demo:

Example 2

Async/await:

const response = await getAncestors(
  'Skłodowska-2',
  {
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
    depth: 2,
  }
);

Promise:

const responsePromise = getAncestors(
  'Skłodowska-2',
  {
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
    depth: 2,
  }
);

responsePromise.then(response => {
  // ...
});

Live demo:

getDescendants

API documentation

Example 1

Async/await:

const response = await getDescendants('Skłodowska-2');

Promise:

const responsePromise = getDescendants('Skłodowska-2')

responsePromise.then(response => {
  // ...
});

Live demo:

Example 2

Async/await:

const response = await getDescendants(
  'Skłodowska-2',
  {
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
    depth: 2,
  }
);

Promise:

const responsePromise = getDescendants(
  'Skłodowska-2',
  {
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
    depth: 1,
  }
);

responsePromise.then(response => {
  // ...
});

Live demo:

getRelatives

API documentation

Example

Async/await:

const response = await getRelatives(
  ['Skłodowska-2'],
  {
    getChildren: true,
    getParents: true,
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth'],
  }
);

Promise:

const responsePromise = getRelatives(
  ['Skłodowska-2'],
  {
    getChildren: true,
    getParents: true,
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth'],
  })

responsePromise.then(response => {
  // ...
});

Live demo:

login (Node.Js)

This login method works only in Node.Js. To log in in a Web application use

Example

const auth = await login('user@example.com', 'P@s$w0Rd');
const response = await getRelatives(['Private-123'], {}, { auth });

Live demo: Replit

login (Web)

API documentation

The Web login only works for apps hosted on https://apps.wikitree.com/. See WikiTree Apps page for details on how to host your app there.

The login flow works as follows:

  1. Redirect the user to the WikiTree login page giving it a URL to redirect back:
navigateToLoginPage('https://apps.wikitree.com/my-app');
  1. Once the user logs in, they will be redirected back to your app with an authcode URL parameter, e.g.
https://apps.wikitree.com/my-app?authcode=abc123abc
  1. The app needs to take this authcode and call clientLogin with it.
clientLogin(authcode);
  1. All subsequent requests to WikiTree will be authenticated.

Use getLoggedInUserName() to get the currently logged in user's profile name.

0.4.0

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago