@catapultsports/amsapi

1.0.5 • Public • Published

Installation

yarn add @catapultsports/amsapi

Peer Dependencies:

  • axios
  • lodash
  • moment-timezone

Usage

import AMSAPI from '@catapultsports/amsapi

let amsApi = new AMSAPI();

getServers()

Returns a list of available servers

Request:

let servers = await amsApi.getServers();

login(username, password, server)

let response = await amsApi.login('email@catapultsports.com', 'yourpassword', 'AU DEV SERVER 1');

// Will throw an exception if login fails

Response:

{
    message: response.message,
    id: 4000,
    email: 'example@email.com',
    name: 'Example User',
    defaultTeam: 1,
    teams: [1, 2],
    token: bf812324-2a71-40a4-ba48-7eb696565610-sportsmed',
    requires2FA: false,
    passcode: 'required',
    blockLogin: false
}

restoreUser

await amsApi.restoreUser(token, server);

getUserDetails()

let userDetails = await amsApi.getUserDetails();

{
    id: 1,
    firstName: 'User',
    lastName: 'Name',
    email: 'user@catapultsports.com',
    phone: '0400 000 000' || null,
    address1: '123 Main Street' || null,
    address2: '123 Main Street' || null,
    city: 'Melbourne' || null,
    state: 'Victoria' || null,
    postcode: '3000' || null,
    birthdate: '2000-01-01' || null,
    gender: 'Male' || null, // Male/Female/null
    height: 180 || null,
    weight: 80 || null,
    eulaAccepted: true,
    timezone: 'Australia/Melbourne',
    profileImage: 'https://ams-au-assets.s3.amazonaws.com/ui/missing-profile-v2.23.27.jpg,
    numUnreadItems: 0,
    passcodeStatus: 'disabled', // disabled/optional/required 
    language: 'en',
    defaultTeam: 27,
    teams: [{
        id: 27
        description: 'The team you are a part of',
        name: 'Your Team',
        language: 'en',
        isStaff: false,
        timezone: 'Australia/Brisbane'
    }]
}

updateUserDetails(details)

Accepts partial updates for [firstName, lastName, birthdate, phone, height, weight, gender, timezone, language]

let updatedUserDetails = await amsApi.updateUserDetails({ firstName: 'NewName', weight: 75 });

Gives same response structure as getUserDetails

createEvent(event, ?options)

event = {
    title: 'Event Title', // Required,
    type: 51, // Required
    start: '2019-01-01 01:00:00', // Required. Perspective time. Any valid moment time will work
    end: '2019-01-01 01:00:00', // Required. Perspective time. Any valid moment time will work
    teamId: 27, // Defaults to null (individual context)
    description: 'Event description',
    mandatory: false,
    timezone: 'Australia/Melbourne', // Will default to user timezone if not set
    repeat: 'onceoff', // [onceoff, daily, weekly, monthly, yearly],
    repeatUntil: '2019-01-08 01:00:00', // Only required if repeat is not onceoff,
    repeatDays: {
        monday: false,
        tuesday: false,
        wednesday: false,
        thursday: false,
        friday: false,
        saturday: false,
        sunday: false
    },
    alert: 'none', [none, min5, min15, min30, min60],
    venue: 15,
    attendingUsers: [4184], // Can only invite users of the same team
    attendingGroups: []
}

// Options is not required, and will default to { notifyUsers: false }
options = {
    notifyUsers: false, // whether notifications will be sent to users of the new event, defaults to false
    recurringStart: '2019-01-01 01:00:00', // if creating a recurring event will return all new events between this and recurringEnd
    recurringEnd: '2019-01-08 01:00:00'
}

let createdEvents = await amsApi.createEvent(event);

createdEvents = {
    [event1Id]: { ...event1 },
    [event2Id]: { ...event2 },
    ...
};

deleteEvents(ids)

Takes both arrays and single event/group ids

let response = await amsApi.deleteEvents(ids);

If passing a single id will return a single response object

{
    id: 1
    success: true,
    error: ''
}

If passing an array of ids will return an array of responses

[{
    id: 1
    success: true,
    error: ''
}, {
    id: 'INVALID ID'
    success: false,
    error: 'Invalid event id'
}]

getTests

let tests = await amsApi.getTests();
{
    [testId]: {
        id: 1
        name: 'Test Title',
        description: 'Test description',
        createdAt: '2019-01-01 00:00:00',
        updatedAt: '2019-01-01 00:00:00',
        canSubmit: true, // Whether the user can submit a test as themselves
        teams: {
            [teamId]: {
                canView: true, // Whether the team allows viewing this test
                canSubmitForOthers: false // Whether the user can submit a test as a different user
            }
        },
        groups: [{ // A section of a test
            id: 1,
            name: 'Group name',
            description: 'Group description',
            elements: [{ // An item/question of a test
                id: 1,
                name: 'Is this a question?',
                description: 'Please chooose an answer',
                type: 'string', // ['date', 'select', 'number', 'string', 'timer', 'range', 'time', 'boolean', 'url'],
                unit: 'Date', // Free text unit description
                items: [{ // Items used in select, range
                    label: 'Item 1',
                    value: 'item_1'
                }],
                validators: {
                    required: false, // Always included
                    min: 0.5, // Only for type 'number'
                    max: 10, // Only for type 'number'
                    dateMustBeFuture: false, // Only for type 'date'. Always included
                    dateMustBePast: false, // Only for type 'date'. Always included
                    type: 'string', ['string', 'number'] // The required value type
                }
            }]
        }]
    }
}

Underlying API

The underlaying api (https://ams-au-live.catapultsports.com/api/v4/docs) is available to be called directly if needed.

Calls not requiring login or restoreUser:

  • getServers()
  • resetPassword(host, email)
  • login(username, password, hostname)
  • restoreUser(token, hostname)

v1 calls:

  • login
  • getUserDetails
  • updateUserDetails
let amsApi = new AMSAPI();
let v1Api = amsApi.api.v1;
let v4Api = amsApi.api.v4;

Readme

Keywords

Package Sidebar

Install

npm i @catapultsports/amsapi

Weekly Downloads

3

Version

1.0.5

License

ISC

Unpacked Size

94.7 kB

Total Files

3

Last publish

Collaborators

  • vikaspiprade
  • johncatapult
  • farzadkhodadadi
  • john.shortland
  • paulbao
  • ams-tech
  • catapult.paulogoncalves
  • dan.prior