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

@openagenda/sdk-js

v2.0.3

Published

OpenAgenda SDK for JavaScript in the browser and Node.js.

Downloads

81

Readme

OpenAgenda SDK for JavaScript in the browser and Node.js.

Summary

Installation

yarn add @openagenda/sdk-js

or

npm i @openagenda/sdk-js

Configuration

In the following examples we use async / await, you can use the promises if your environment does not allow it.

Before any operation you have to connect, the token is refreshed automatically as soon as it is necessary.

const OaSdk = require('@openagenda/sdk-js');

const oa = new OaSdk({
  publicKey: 'YOUR-PUBLIC-KEY',
  secretKey: 'YOUR-PRIVATE-KEY'
});
await oa.connect();

The public key is used for get method.
The private key is used for all create, update, and delete methods.

API

For more information about data formats please refer to the API documentation on our help center.

Events

const agendaUid = 12345678;
const eventUid = 87654321;

const event = await oa.events.get(agendaUid, eventUid);
const eventUid = 87654321;

const event = await oa.events.list(agendaUid, { sort: 'updatedAt.desc' });
const agendaUid = 12345678;

const event = await oa.events.create(agendaUid, {
  slug: 'a-title',
  title: {
    fr: 'Un titre',
    en: 'A title'
  },
  description: {
    fr: 'La description de votre événement',
    en: 'The description of your event'
  },
  locationUid: 78372099,
  timings: [
    {
      begin: moment(),
      end: moment().add(1, 'hour')
    }, {
      begin: moment().add(1, 'day'),
      end: moment().add(1, 'day').add(1, 'hour')
    }
  ]
});

In this example we use moment for manage the timings, but you can also use the native Date object.

const agendaUid = 12345678;
const eventUid = 87654321;

const updatedEvent = await oa.events.update(
  agendaUid,
  eventUid,
  {
    ...event,
    title: {
      fr: 'Titre mise à jour',
      en: 'Updated title'
    }
  }
);
const agendaUid = 12345678;
const eventUid = 87654321;

const patchedEvent = await oa.events.patch(
  agendaUid,
  eventUid,
  {
    title: {
      fr: 'Titre mise à jour',
      en: 'Updated title'
    }
  }
);
const agendaUid = 12345678;
const eventUid = 87654321;

const deletedEvent = await oa.events.delete(agendaUid, eventUid);

Locations

const agendaUid = 12345678;
const locationUid = 87654321;

const location = await oa.locations.get(agendaUid, locationUid);
const agendaUid = 12345678;

const location = await oa.locations.list(agendaUid, { sort: 'updatedAt.desc' });
const agendaUid = 12345678;

const location = await oa.locations.create(agendaUid, {
  name: 'Gare Meuse TGV',
  address: 'Lieu dit Le Cugnet, 55220 Les Trois-Domaines',
  latitude: 48.9736458,
  longitude: 5.2723537
});
const agendaUid = 12345678;
const locationUid = 87654321;

const location = await oa.locations.update(agendaUid, locationUid, {
  ...location,
  address: 'Lieu dit Le Cugnet, 55220 Les Trois-Domaines'
});
const agendaUid = 12345678;
const locationUid = 87654321;

const location = await oa.locations.patch(agendaUid, locationUid, {
  address: 'Lieu dit Le Cugnet, 55220 Les Trois-Domaines',
});
const agendaUid = 12345678;
const locationUid = 87654321;

const location = await oa.locations.delete(agendaUid, locationUid);

Errors

Whatever the method if the error comes from the API the error will be in error.response and its JSON content in error.response.data.

If you use async / await then you can use try / catch otherwise you will have to use .catch.

async / await example:

try {
  await oa.events.create(12345678, {
    slug: 'a-title',
    description: {
      fr: 'La description de votre événement',
      en: 'The description of your event'
    },
    locationUid: 87654321,
    timings: [
      {
        begin: moment(),
        end: moment().add(1, 'hour')
      }, {
        begin: moment().add(1, 'day'),
        end: moment().add(1, 'day').add(1, 'hour')
      }
    ]
  });
} catch (e) {
  expect(e.response.data).to.be.eql({
    errors: [
      {
        field: 'title',
        code: 'required',
        message: 'at least one language entry is required'
      }
    ]
  });
}

Promise example:

oa.events.create(12345678, {
  slug: 'a-title',
  description: {
    fr: 'La description de votre événement',
    en: 'The description of your event'
  },
  locationUid: 87654321,
  timings: [
    {
      begin: moment(),
      end: moment().add(1, 'hour')
    }, {
      begin: moment().add(1, 'day'),
      end: moment().add(1, 'day').add(1, 'hour')
    }
  ]
})
  .then(result => {
    //
  })
  .catch(error => {
    expect(error.response.data).to.be.eql({
      errors: [
        {
          field: 'title',
          code: 'required',
          message: 'at least one language entry is required'
        }
      ]
    });
  });