# @happy-horizon/f19-sdk-js

> Javascript SDK for F19 digital reporting platform

Latest version **2.4.1** (published 2024-02-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @happy-horizon/f19-sdk-js
pnpm add @happy-horizon/f19-sdk-js
yarn add @happy-horizon/f19-sdk-js
bun add @happy-horizon/f19-sdk-js
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.4.1 |
| Published | 2024-02-21 |
| First published | 2023-08-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.8.2 |
| Dependencies | 2 |
| Unpacked size | 214.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | gracious |
| Maintainers | j.kabuta, jaystewart, chesneyb, samtaal-gracious, surajsanchit |

## Links

- npm: https://www.npmjs.com/package/@happy-horizon/f19-sdk-js
- Repository: https://github.com/Happy-Horizon/f19-sdk-js
- Homepage: https://github.com/Happy-Horizon/f19-sdk-js#readme
- Issues: https://github.com/Happy-Horizon/f19-sdk-js/issues
- npm.io page: https://npm.io/package/@happy-horizon/f19-sdk-js

## Dependencies (2)

- [jose](https://npm.io/package/jose.md) ^5.1.1
- [xml2js](https://npm.io/package/xml2js.md) ^0.6.2

## Recent versions

- 2.4.1 (latest) — 2024-02-21
- 2.4.0 — 2024-02-15
- 2.3.0 — 2024-02-14
- 2.2.9 — 2024-02-12
- 2.2.8 — 2024-02-12
- 2.2.7-0 — 2024-02-09
- 2.2.6 — 2024-02-09
- 2.2.5 — 2024-02-07
- 2.2.4 — 2024-02-07
- 2.2.3 — 2024-02-06
- 2.2.2 — 2024-02-06
- 2.2.1 — 2024-02-02
- 2.2.0 — 2024-02-02
- 2.1.1 — 2024-01-26
- 2.1.0 — 2024-01-22
- … 16 more at https://npm.io/package/@happy-horizon/f19-sdk-js/versions

## README

# F19 SDK JS

[![Language](https://img.shields.io/badge/language-javascript-yellow.svg)](https://git.gracious.nl/f19/f19-sdk-js) [![Language](https://img.shields.io/badge/language-typescript-blue.svg)](https://git.gracious.nl/f19/f19-sdk-js)

Javascript SDK for the F19 digital reporting platform.

## Getting Started

## How to install

### Installing

A step by step series of examples that tell you how to get a development env running

```bash
npm install @happy-horizon/f19-sdk-js
```

> ⚠️ This SDK uses the Fetch API under the hood. If your environment doesn't support it, you need to install a polyfill like [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch) or [node-fetch](https://github.com/node-fetch/node-fetch)

## Usage

Import the package using ES6 imports or CommonJS require

```javascript
import F19 from "@happy-horizon/f19-sdk-js";
```

```javascript
const F19 = require("@happy-horizon/f19-sdk-js");
```

Create a new instance of the F19 class with your API key, Client Id, and base URL

```javascript
const client = new F19({
    apiKey: "[F19_API_KEY]",
    clientId: "[F19_CLIENT_ID]",
    baseUrl: "[F19_BASE_URL]"
});
```

Now you can access all anonymous methods using the client object.

If you want to access the personal methods, you need to log in first.
You can do this by redirecting the user to the F19 login page and then redirecting them back after logging in using a callback URL.

```javascript
// Define the callback URL (you would replace this with your actual callback URL)
const loginUrl = client.getAuthUrl("https://your.callback.url");
```

After the user has logged in, they will be redirected back to your callback URL with impersonation options in the request body.
You can use these impersonation options to create a new instance of the client that can access the personal methods.

```javascript
const client = new F19(
    {
        apiKey: "[F19_API_KEY]",
        clientId: "[F19_CLIENT_ID]",
        baseUrl: "[F19_BASE_URL]"
    },
    {
        userId: body.UserId,
        keyThumbprint: body.KeyThumbprint,
        cacheDifferentiator: body.CacheDifferentiator,
        authorizationToken: body.AuthorizationToken
    }
);
```

## Available methods

| Grouping         | Method Name       | Parameters                              |
| ---------------- | ----------------- | --------------------------------------- |
| articles         | getAllByProjectId | projectId: string                       |
|                  | getById           | articleId: string                       |
| assets           | getImageByName    | projectId: string, name: string         |
|                  | getDownloadByName | projectId: string, name: string         |
|                  | getBlobByToken    | token: string                           |
| channel          | getAll            |                                         |
| charts           | getAll            | projectId: string                       |
|                  | getById           | chartId: string                         |
| downloads        | getById           | id: string                              |
|                  | getAllByProjectId | projectId: string                       |
| facetNavigations | getAll            | projectId: string                       |
|                  | getById           | facetId: string                         |
| images           | getAll            | projectId: string                       |
|                  | getById           | imageId: string                         |
| nonce            | getNonce          |                                         |
| projects         | getAll            |                                         |
|                  | getById           | id: string                              |
| reports          | getById           | id: string                              |
|                  | getAllByProjectId | id: string                              |
| tables           | getAll            | projectId: string                       |
|                  | getById           | tableId: string                         |
| tokens           | tokenRequest      | url: string, authorizationToken: string |
|                  | getPersonal       | authorizationToken: string              |
|                  | getAnonymous      | authorizationToken: string              |
| websites         | getAll            |                                         |
|                  | getByAlias        | alias: string                           |
|                  | getCurrent        |                                         |

### Example usage

```javascript
// Define the projectId (you would replace this with your actual project ID)
const projectId = "your_project_id_here";

// Call the getAllByProjectId method
client.article
    .getAllByProjectId(projectId)
    .then(result => {
        // Handle the result here
        console.log("Result:", result);
    })
    .catch(error => {
        // Handle any errors that occur
        console.error("Error:", error);
    });
```

---
_Source: https://npm.io/package/@happy-horizon/f19-sdk-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
