UNPKG

@planet-a/affinity-node

Version:
111 lines (110 loc) 3.9 kB
import axios from 'axios'; import { Auth } from './auth.js'; import { RateLimit } from './rate_limit.js'; import { Lists } from './lists.js'; import { Fields } from './fields.js'; import { FieldValues } from './field_values.js'; import { FieldValueChanges } from './field_value_changes.js'; import { Organizations } from './organizations.js'; import { Persons } from './persons.js'; import { EntityFiles } from './entity_files.js'; import { Notes } from './notes.js'; export { EntityType, FieldValueType, RoleId } from './lists.js'; export { AffinityApiError } from './errors.js'; export { ActionType } from './field_value_changes.js'; export { PersonType } from './persons.js'; /** * @module */ export class Affinity { /** * @param apiKey The Affinity API key. [How to get yours](https://support.affinity.co/hc/en-us/articles/360032633992-How-to-obtain-your-API-Key). * @param axiosInstance An axios instance. You can use the default axios instance or bring your own. If you bring your own, it won't be reconfigured. */ constructor(apiKey, axiosInstance) { Object.defineProperty(this, "axios", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "auth", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "rateLimit", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "lists", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "fields", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "fieldValues", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "fieldValueChanges", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "organizations", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "persons", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "entityFiles", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "notes", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.axios = axiosInstance || axios.create(); this.axios.defaults.headers.common['X-Requested-With'] = '@planet-a/affinity-node'; this.axios.defaults.auth = { username: '', password: apiKey, }; this.axios.defaults.baseURL = 'https://api.affinity.co'; this.lists = new Lists(this.axios); this.rateLimit = new RateLimit(this.axios); this.auth = new Auth(this.axios); this.fields = new Fields(this.axios); this.fieldValues = new FieldValues(this.axios); this.fieldValueChanges = new FieldValueChanges(this.axios); this.organizations = new Organizations(this.axios); this.persons = new Persons(this.axios); this.entityFiles = new EntityFiles(this.axios); this.notes = new Notes(this.axios); } }