0.1.4 • Published 3 years ago
@epicdm/gigwage v0.1.4
Beta - Currently in Development
Adding convenience methods for certain endpoints, eg: listSubscriptions. Not all methods implemented yet. Please check back soon.
Installation
yarn add @epicdm/gigwage
npm install @epicdm/gigwageSee Gigwage Developer Documentation
API Client usage, see examples
import GigwageService, { Contractor, Subscription } from '../src/gigwage';
const gigwageService = new GigwageService({
  config: {
    apiKey: 'YOUR_API_KEY',
    apiSecret: 'YOUR_API_SECRET',
    apiEnvironment: 'sandbox',
  },
});
/* Exposes signed axios request methods:
  gigwageService.get
  gigwageService.post
  gigwageService.put
  gigwageService.patch
  gigwageService.del
*/
gigwageService.get<{ contractors: Contractor[] }>("api/v1/contractors")
  .then((response) => {
    const contractors = response.data.contractors;
  });
gigwageService.post<{ contractor: Contractor }>("api/v1/contractors", {
  contractor: {
    first_name: 'John',
    last_name: 'Doe',
    email: 'john@doe.com',
  }
}).then((response) => {
  if (response.data.error) {
    /* Axios handled error, includes validation error response:
    {
      "error": "Validation Failed",
      "errors": [
        "Email missing",
      ]
    }
    */
  }
  const contractor = response.data.contractor;
});
// Reactivate Subscription
gigwageService.put<{ subscription: Subscription }>(`api/v1/subscriptions/13`)
  .then((response) => {
    const subscription = response.data.subscription;
  });
// Delete Subscription
gigwageService.del<{ subscription: Subscription }>(`api/v1/subscriptions/13`)
  .then((response) => {
    const subscription = response.data.subscription;
  });  Express Middleware Usage, see examples
route.post(
  `/gigwage/payment`,
  gigwageService.bodyParser(), // need raw and JSON body
  gigwageService.validateWebhook(), // validate webhook signature
  async (request, response) => {
    try {
      // do something with the request, its been validated
      response.status(200).send(`I did it!`);
    } catch (err: any) {
      console.log(err);
      response.status(500).send(`Webhook Error`);
      return;
    }
  },
);Development Getting started
Installation
Clone this repository:
git clone https://github.com/epicdigitalmedia/epic-gigwageOpen the directory and run the script line:
cd epic-gigwageyarn # or npm i🤝 Contributing
Contributions, issues and feature requests are welcome!Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!
📝 License
Copyright © 2022 Epic Digital Interactive Media LLC. This project is MIT licensed.