npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

afp-apicore-sdk

v1.1.12

Published

Node helper functions to authenticate and fetch AFP API apicore

Downloads

21

Readme

ApiCore API

NodeJS Lint, Build and Test NPM publish CD workflow

This project is aimed to help javascript developers use the AFP API ApiCore.

It provides authentication, searching for documents function, and online news product.

Getting Started

This package is available both for NodeJS and browsers. That's why two versions are available on the ./dist directory.

Prerequisites

Read the API documentation, and ask for an API Key and credentials.

Installing

Node

npm install --save afp-apicore-sdk

const ApiCore = require('afp-apicore-sdk')
// OR using import
import ApiCore from 'afp-apicore-sdk'

Browser

<script src="./dist/afp-apicore-sdk.umd.js"></script>

Let's start using it

// Initialize the API
const apicore = new ApiCore({
  clientId: 'YOUR_CLIENT_ID',
  clientSecret: 'YOUR_CLIENT_SECRET',
  saveToken: token => {
    // You can eventually save the token to be used later
    console.log(token)
  }
})

// Search for latest documents
apicore
  .authenticate({
    username: 'YOUR_USERNAME',
    password: 'YOUR_PASSWORD'
  })
  .then(() => apicore.search())
  .then(({ documents }) => {
    console.log(documents)
  })

// Get a specific document
apicore
  .get('A_SPECIFIC_UNO')
  .then(document => {
    console.log(document)
  })

// Look for similar documents
apicore
  .mlt('A_SPECIFIC_UNO')
  .then(({ documents }) => {
    console.log(documents)
  })

// Display the most used slugs
apicore
  .list('slug')
  .then(({ keywords }) => {
    console.log(keywords)
  })

Query parser

The above request use default parameters stored in ./src/default-search-params.js

You can pass your own parameters to the search function, that will overide the defaults :

apicore.search({
  products: ['news'],
  langs: ['fr'],
  urgencies: [1, 2, 3, 4],
  query: 'french politics',
  size: 10,
  dateFrom: '2012-01-01',
  dateTo: 'now',
  sortField: 'published',
  sortOrder: 'desc'
})

The query parameter can be used to look precisely for a field (title:Macron) and may include logical parameters (Macron OR Merkel, Macron AND NOT Merkel, title:(Macron OR Merkel) AND country:fra).

Integrate notification in your workflow.

Apicore have a service to send notification to a subscribed external service like mail or http endpoint.

To use it

let notification = new ApiCoreNotificationCenter(apicore)

notificationCenter.registerService({
  name: 'my-service-notification',
  type: 'mail',
  datas: {
    address: '[email protected]'
  }
}).then(uno => {
  console.log(`service created, uno: ${uno}`)

  const dontDisturb = true

  let subscription = notificationCenter.buildSubscription({
    langs: 'fr',
    urgencies: 2,
    classes: 'text'
  }, dontDisturb, {
    startTime: '22:30:00',
    endTime: '07:00:00',
    tz: 'Europe/Paris'
  })

  notificationCenter.addSubscription('sample-subscription', 'my-service-notification', subscription).then(uno => {
    console.log(`subscription created, uno: ${uno}`)
  }).catch(e => {
    console.error(e)
  })

}).catch(e => {
  console.error(e)
})

Development

Clone the repository, then npm install

Build and minify your work for browsers and node with npm run build

Running the tests

Just npm test to execute all tests in ./tests

You will need some environment variables in a .env file :

APICORE_BASE_URL=
APICORE_API_KEY=
APICORE_CLIENT_ID=
APICORE_CLIENT_SECRET=
APICORE_USERNAME=
APICORE_PASSWORD=
APICORE_CUSTOM_AUTH_URL=https://

Built With

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details