Giter VIP home page Giter VIP logo

eventfarm / javascript-sdk Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 1.0 597 KB

TypeScript client library written for the Event Farm API. Works great with Angular, React.js, Vue.js or <insert front end framework here>, as well as any backend, including Express.js, Nest.js, or any other server side Node.js framework.

Home Page: https://www.eventfarm.com

License: MIT License

TypeScript 100.00%
typescript javascript event-farm node client-library

javascript-sdk's Introduction

Event Farm Logo
Official Event Farm TypeScript SDK

Installation

npm install --save @eventfarm/javascript-sdk

Usage

Client Side Application (React, Angular, Vue, etc.)

You are going to need to get an access token JWT using the Event Farm OAuth.

import { FrontEndClient } from '@eventfarm/javascript-sdk/dist/FrontEndClient';
import { ClientAccessToken } from '@eventfarm/javascript-sdk/dist/Rest/Client/ClientAccessToken';

const jwtResponseFromOauth: string = 'crazy-jwt-string-from-ef-oauth-login';

const client = new FrontEndClient(
  ClientAccessToken.createFromJWT(jwtResponseFromOauth)
);

async function listEvents(userId: string): Promise<{}> {
  return await client.useCaseFactory.Event().ListEventsForUser(userId);
}

listEvents('my-user-id').then(apiResponse => console.log(apiResponse));

Server Side (Express, Koa, etc.)

See Example

OAuth is done using the Password Grant. You are going to need a Client Id and Secret that will be provided by Event Farm.

import { BackEndClient } from '@eventfarm/javascript-sdk/dist/BackEndClient';

const client = new BackEndClient(
    'client_id', // required string
    'client_secret', // required string
    'audience', // required string
    'loginBaseUrl', // default: ''https://eventfarm.us.auth0.com/api/v2/oauth/token'
    'apiBaseUrl', // default: 'https://app.eventfarm.com/api'
);

async function listEvents(userId: string): Promise<{}> {
  return await client.useCaseFactory.Event().ListEventsForUser(userId);
}

listEvents('my-user-id').then(apiResponse => console.log(apiResponse));

Responses

Responses are following the Json API Spec. Please see the format/spec guide for further details.

{
  "data": {
    "type": "Event",
    "id": "7fff5387-0000-45a5-ae48-1d05a7175b93",
    "attributes": {
      "name": "Awesome Test Party",
      "email": "[email protected]",
      "contactEmail": "[email protected]",
      "guestLimit": -1,
      "type": {
        "slug": "eventfarm",
        "name": "Event Farm",
        "description": null,
        "isEventFarm": true,
        "isCio": false,
        "isListly": false,
        "isDnc": false,
        "isRnc": false,
        "isRslc": false,
        "isSundance": false
      },
      "eventAttributes": {
        "hasDistribute": true,
        "hasDonate": true,
        "hasFee": true,
        "hasEditName": true,
        "hasReveal": true,
        "hasAllowNotes": true,
        "hasDuplicateEmails": true,
        "hasNavigation": true,
        "hasSocialMedia": true,
        "hasSocialMediaBar": true,
        "hasMapLocation": true,
        "hasShowDescription": true,
        "hasIPadPurchase": false,
        "hasSimpleLayout": true,
        "hasLabelPrint": false,
        "hasSkipEventAllocateDisplay": true,
        "hasGeoRestrict": true,
        "hasVisaCheckout": true,
        "hasArchived": false,
        "hasGuestCanChangeResponse": true,
        "hasEfxEnabled": false
      },
      "userFields": {
        "hasAddress": false,
        "hasCompany": false,
        "hasPhone": false,
        "hasTitle": false,
        "hasCountry": false,
        "hasPosition": false
      },
      "startTime": {
        "timestamp": 1643400000,
        "timezone": "America/Los_Angeles",
        "locale": "en_US",
        "date": {
          "short": "1/28/22",
          "medium": "January 28, 2022",
          "long": "Friday, January 28, 2022"
        },
        "time": {
          "short": "12:00 PM",
          "medium": "12:00 PM PST",
          "long": "12:00:00 PM PST"
        },
        "short": "1/28/22, 12:00 PM PST",
        "medium": "January 28, 2022 at 12:00 PM PST",
        "long": "Friday, January 28, 2022 at 12:00 PM PST"
      },
      "endTime": {
        "timestamp": 1643486400,
        "timezone": "America/Los_Angeles",
        "locale": "en_US",
        "date": {
          "short": "1/29/22",
          "medium": "January 29, 2022",
          "long": "Saturday, January 29, 2022"
        },
        "time": {
          "short": "12:00 PM",
          "medium": "12:00 PM PST",
          "long": "12:00:00 PM PST"
        },
        "short": "1/29/22, 12:00 PM PST",
        "medium": "January 29, 2022 at 12:00 PM PST",
        "long": "Saturday, January 29, 2022 at 12:00 PM PST"
      },
      "altKeyword": "mediumeventp1",
      "venue": {
        "name": null,
        "address": null,
        "artistName": null,
        "artistDeposit": 0,
        "checkName": null,
        "flatPercentage": 0,
        "flatFee": 0,
        "memo": null
      },
      "isEFxEnabled": false,
      "defaultSitePage": null,
      "created": {
        "createdAt": 1516128284,
        "ip4Created": "127.0.0.1"
      },
      "modified": {
        "modifiedAt": 1516128284,
        "ip4Modified": null
      },
      "mapSourceType": {
        "slug": "google",
        "name": "Google",
        "description": "Google Maps",
        "isGoogle": true,
        "isYahoo": false,
        "isBing": false
      }
    },
    "meta": {
      "isInitialized": true
    },
    "links": {
      "self": "https://eventfarm.com/api/v2/Event/UseCase/GetEvent?eventId=7fff5387-0000-45a5-ae48-1d05a7175b93"
    },
    "relationships": {
      "pool": {
        "type": "Pool",
        "id": "7fff1f7a-0000-45a5-a6b7-9123da6f4aff",
        "meta": {
          "isInitialized": false
        },
        "links": {
          "self": "https://eventfarm.com/api/v2/Pool/UseCase/GetPool?poolId=7fff1f7a-0000-45a5-a6b7-9123da6f4aff"
        }
      },
      "stacks": [
        {
          "type": "Stack",
          "id": "7fffb628-0000-45a5-ae48-4a001dbd6d01",
          "attributes": {
            "id": "7fffb628-0000-45a5-ae48-4a001dbd6d01",
            "send": "invite,confirm,decline",
            "inviteEmailId": "7fff3d1a-0000-45a5-ae48-4e08d86c122b",
            "confirmEmailId": "7fff3d1a-0000-45a5-ae48-4e0f60015a83",
            "declineEmailId": "7fff3d1a-0000-45a5-ae48-4f03e0c52a9f",
            "serviceFee": 0,
            "price": 0,
            "quantity": 300,
            "maxQuantity": 10,
            "openingAt": 1516041900,
            "closingAt": 1643485500,
            "isTransferable": true,
            "isDeleted": false,
            "deletedAt": null,
            "stackMethodType": {
              "slug": "invite-to-rsvp-fcfs",
              "name": "Invite to RSVP (FCFS)",
              "description": null,
              "isPublicRegistration": false,
              "isPublicPurchase": false,
              "isInviteToRegister": false,
              "isInviteToPurchase": false,
              "isInviteToRSVP": false,
              "isInviteToRegisterFCFS": false,
              "isInviteToPurchaseFCFS": false,
              "isInviteToRSVPFCFS": true,
              "isInvitation": true,
              "isFirstComeFirstServe": true,
              "isAnyInviteToPurchase": false,
              "isAnyInviteToRegister": false,
              "isAnyInviteToRSVP": true
            },
            "created": {
              "createdAt": 1516128329,
              "ip4Created": "172.18.0.1"
            },
            "modified": {
              "modifiedAt": 1516128337,
              "ip4Modified": "172.18.0.1"
            }
          },
          "extraAttributes": {
            "availabilityCounts": {
              "totalQuantity": 300,
              "totalUsed": 0,
              "totalUnused": 300,
              "totalAvailable": 300,
              "percentUsed": 0,
              "percentUnused": 100,
              "totalAffirmed": 0,
              "totalUnaffirmed": 300,
              "percentAffirmed": 0,
              "percentUnaffirmed": 100,
              "total": 0,
              "assigned": 0,
              "purchased": 0,
              "confirmed-by-rsvp": 0,
              "declined-by-rsvp": 0,
              "left-behind": 0,
              "not-yet-purchased": 0,
              "registered": 0,
              "unconfirmed": 0,
              "recycled": 0,
              "not-yet-registered": 0
            }
          },
          "meta": {
            "isInitialized": true
          },
          "links": {
            "self": "https://eventfarm.com/api/v2/Stack/UseCase/GetStack?stackId=7fffb628-0000-45a5-ae48-4a001dbd6d01"
          },
          "relationships": {
            "ticketType": {
              "type": "TicketType",
              "id": "7fff36ce-0000-45a5-ae48-3918d3759d9d",
              "attributes": {
                "id": "7fff36ce-0000-45a5-ae48-3918d3759d9d",
                "name": "VIP",
                "code": "",
                "description": null,
                "quantity": 300,
                "sortOrder": 1,
                "isDeleted": false,
                "deletedAt": null,
                "created": {
                  "createdAt": 1516128313,
                  "ip4Created": "172.18.0.1"
                },
                "modified": {
                  "modifiedAt": 1516128313,
                  "ip4Modified": null
                }
              },
              "meta": {
                "isInitialized": true
              },
              "links": {
                "self": "https://eventfarm.com/api/v2/Stack/UseCase/GetTicketType?ticketTypeId=7fff36ce-0000-45a5-ae48-3918d3759d9d"
              }
            }
          }
        }
      ],
      "ticketBlocks": [
        {
          "type": "TicketBlock",
          "id": "7fff6ce5-0000-45a5-ae49-390fe1d99c88",
          "attributes": {
            "name": "Medium Event P1 - TB2",
            "emailText": null,
            "isBlacklistEnabled": false,
            "isDeleted": false,
            "deletedAt": null,
            "created": {
              "createdAt": 1516128569,
              "ip4Created": "127.0.0.1"
            },
            "modified": {
              "modifiedAt": 1516128569,
              "ip4Modified": null
            }
          },
          "extraAttributes": {
            "allotmentCounts": [
              {
                "allotmentId": "7fffa0bd-0000-45a5-ae49-3918e32c0a59",
                "stackId": "7fffb628-0000-45a5-ae48-4a001dbd6d01",
                "ticketBlockId": "7fff6ce5-0000-45a5-ae49-390fe1d99c88",
                "ticketTypeName": "VIP",
                "stackMethodType": {
                  "slug": "invite-to-rsvp-fcfs",
                  "name": "Invite to RSVP (FCFS)",
                  "description": null,
                  "isPublicRegistration": false,
                  "isPublicPurchase": false,
                  "isInviteToRegister": false,
                  "isInviteToPurchase": false,
                  "isInviteToRSVP": false,
                  "isInviteToRegisterFCFS": false,
                  "isInviteToPurchaseFCFS": false,
                  "isInviteToRSVPFCFS": true,
                  "isInvitation": true,
                  "isFirstComeFirstServe": true,
                  "isAnyInviteToPurchase": false,
                  "isAnyInviteToRegister": false,
                  "isAnyInviteToRSVP": true
                },
                "invitationCounts": {
                  "totalUsed": 0,
                  "firstComeFirstServeOutstanding": 0,
                  "totalQuantity": 10,
                  "totalRemaining": 10
                }
              },
              {
                "allotmentId": "7fffa0bd-0000-45a5-ae49-3920c5604384",
                "stackId": "7fffb628-0000-45a5-ae48-6c08880cbd00",
                "ticketBlockId": "7fff6ce5-0000-45a5-ae49-390fe1d99c88",
                "ticketTypeName": "GA",
                "stackMethodType": {
                  "slug": "invite-to-rsvp-fcfs",
                  "name": "Invite to RSVP (FCFS)",
                  "description": null,
                  "isPublicRegistration": false,
                  "isPublicPurchase": false,
                  "isInviteToRegister": false,
                  "isInviteToPurchase": false,
                  "isInviteToRSVP": false,
                  "isInviteToRegisterFCFS": false,
                  "isInviteToPurchaseFCFS": false,
                  "isInviteToRSVPFCFS": true,
                  "isInvitation": true,
                  "isFirstComeFirstServe": true,
                  "isAnyInviteToPurchase": false,
                  "isAnyInviteToRegister": false,
                  "isAnyInviteToRSVP": true
                },
                "invitationCounts": {
                  "totalUsed": 0,
                  "firstComeFirstServeOutstanding": 0,
                  "totalQuantity": 300,
                  "totalRemaining": 300
                }
              }
            ]
          },
          "meta": {
            "isInitialized": true
          },
          "links": {
            "self": "https://eventfarm.com/api/v2/TicketBlock/UseCase/GetTicketBlock?ticketBlockId=7fff6ce5-0000-45a5-ae49-390fe1d99c88"
          }
        }
      ]
    }
  }
}

Paginated

{
  "meta": {
    "totalPages": 2,
    "totalResults": 2,
    "totalResultsReturned": 1,
    "currentPage": 1,
    "itemsPerPage": 1,
    "executedAt": 1526599136
  },
  "links": {
    "self": "https://eventfarm.com/api/v2/Event/UseCase/ListEventsForUser?eventDateFilterType=current-future\u0026itemsPerPage=1\u0026userId=7fff1483-0000-4578-ad31-f6114a033eb7",
    "first": "https://eventfarm.com/api/v2/Event/UseCase/ListEventsForUser?eventDateFilterType=current-future\u0026itemsPerPage=1\u0026userId=7fff1483-0000-4578-ad31-f6114a033eb7\u0026page=1",
    "last": "https://eventfarm.com/api/v2/Event/UseCase/ListEventsForUser?eventDateFilterType=current-future\u0026itemsPerPage=1\u0026userId=7fff1483-0000-4578-ad31-f6114a033eb7\u0026page=2",
    "next": "https://eventfarm.com/api/v2/Event/UseCase/ListEventsForUser?eventDateFilterType=current-future\u0026itemsPerPage=1\u0026userId=7fff1483-0000-4578-ad31-f6114a033eb7\u0026page=1"
  },
  "data": [
    {
      "type": "Event",
      "id": "7fff5387-0000-4578-ae9c-921df4f75d90",
      "attributes": {
        "name": "Awesome Test Party",
        "email": "[email protected]",
        "contactEmail": "[email protected]",
        "guestLimit": -1,
        "type": {
          "slug": "eventfarm",
          "name": "Event Farm",
          "description": null,
          "isEventFarm": true,
          "isCio": false,
          "isListly": false,
          "isDnc": false,
          "isRnc": false,
          "isRslc": false,
          "isSundance": false
        },
        "eventAttributes": {
          "hasDistribute": false,
          "hasDonate": false,
          "hasFee": false,
          "hasEditName": false,
          "hasReveal": false,
          "hasAllowNotes": false,
          "hasDuplicateEmails": true,
          "hasNavigation": true,
          "hasSocialMedia": true,
          "hasSocialMediaBar": true,
          "hasMapLocation": false,
          "hasShowDescription": true,
          "hasIPadPurchase": false,
          "hasSimpleLayout": true,
          "hasLabelPrint": false,
          "hasSkipEventAllocateDisplay": true,
          "hasGeoRestrict": false,
          "hasVisaCheckout": false,
          "hasArchived": false,
          "hasGuestCanChangeResponse": true,
          "hasEfxEnabled": false
        },
        "userFields": {
          "hasAddress": false,
          "hasCompany": false,
          "hasPhone": false,
          "hasTitle": false,
          "hasCountry": false,
          "hasPosition": false
        },
        "startTime": {
          "timestamp": 1659043920,
          "timezone": "America/Los_Angeles",
          "locale": "en_US",
          "date": {
            "short": "7/28/22",
            "medium": "July 28, 2022",
            "long": "Thursday, July 28, 2022"
          },
          "time": {
            "short": "2:32 PM",
            "medium": "2:32 PM PST",
            "long": "2:32:00 PM PDT"
          },
          "short": "7/28/22, 2:32 PM PST",
          "medium": "July 28, 2022 at 2:32 PM PST",
          "long": "Thursday, July 28, 2022 at 2:32 PM PST"
        },
        "endTime": {
          "timestamp": 1659130320,
          "timezone": "America/Los_Angeles",
          "locale": "en_US",
          "date": {
            "short": "7/29/22",
            "medium": "July 29, 2022",
            "long": "Friday, July 29, 2022"
          },
          "time": {
            "short": "2:32 PM",
            "medium": "2:32 PM PST",
            "long": "2:32:00 PM PDT"
          },
          "short": "7/29/22, 2:32 PM PST",
          "medium": "July 29, 2022 at 2:32 PM PST",
          "long": "Friday, July 29, 2022 at 2:32 PM PST"
        },
        "altKeyword": "awesome-test-party",
        "venue": {
          "name": "Event Farm HQ",
          "address": "2403 Main Street, Santa Monica, CA",
          "artistName": null,
          "artistDeposit": 0,
          "checkName": null,
          "flatPercentage": 0,
          "flatFee": 0,
          "memo": null
        },
        "isEFxEnabled": false,
        "defaultSitePage": null,
        "created": {
          "createdAt": 1468963985,
          "ip4Created": "172.18.0.1"
        },
        "modified": {
          "modifiedAt": 1516139911,
          "ip4Modified": "172.18.0.1"
        },
        "mapSourceType": {
          "slug": "google",
          "name": "Google",
          "description": "Google Maps",
          "isGoogle": true,
          "isYahoo": false,
          "isBing": false
        }
      },
      "meta": {
        "isInitialized": true
      },
      "links": {
        "self": "https://eventfarm.com/api/v2/Event/UseCase/GetEvent?eventId=7fff5387-0000-4578-ae9c-921df4f75d90"
      },
      "relationships": {
        "pool": {
          "type": "Pool",
          "id": "7fff1f7a-0000-4578-ad49-681e5374350c",
          "meta": {
            "isInitialized": false
          },
          "links": {
            "self": "https://eventfarm.com/api/v2/Pool/UseCase/GetPool?poolId=7fff1f7a-0000-4578-ad49-681e5374350c"
          }
        }
      }
    }
  ]
}

javascript-sdk's People

Contributors

barryross avatar dependabot[bot] avatar jasonraimondi avatar jdodsoncollins avatar kevinthrailkill avatar toddcornett avatar

Watchers

 avatar  avatar  avatar

Forkers

jasonraimondi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.