@planet-a/affinity-node
Version:
API wrapper for the affinity.co API
83 lines (82 loc) • 2.98 kB
JavaScript
import { defaultTransformers } from './axios_default_transformers.js';
import { fieldValueChangesUrl } from './urls.js';
/**
* Enum for Action Type.
*/
export var ActionType;
(function (ActionType) {
/**
* Represents the action type for creating a field value change.
*/
ActionType[ActionType["CREATE"] = 0] = "CREATE";
/**
* Represents the action type for deleting a field value change.
*/
ActionType[ActionType["DELETE"] = 1] = "DELETE";
/**
* Represents the action type for updating a field value change.
*/
ActionType[ActionType["UPDATE"] = 2] = "UPDATE";
})(ActionType || (ActionType = {}));
/**
* Field value changes allow you to see historical changes to the values of fields in Affinity.
* This is especially useful for tracking progress through statuses (e.g. Lead --> Closed Won).
*
* *Supported field types*:
* Not all fields can track historical changes.
* Fields that are automatically created and "enriched" by Affinity do not support change tracking.
*
* Among fields that are not enriched, only the ones with the following data types support change tracking:
*
* Multi-valued fields:
* - {@link FieldValueType.PERSON}
* - {@link FieldValueType.ORGANIZATION}
* - {@link FieldValueType.NUMBER}
* - {@link FieldValueType.LOCATION}
*
* Single-valued fields:
* - {@link FieldValueType.PERSON}
* - {@link FieldValueType.ORGANIZATION}
* - {@link FieldValueType.NUMBER}
* - {@link FieldValueType.DATE}
* - {@link FieldValueType.LOCATION}
* - {@link FieldValueType.RANKED_DROPDOWN}
*
* You can also see if a field does so by looking at the {@link Field.track_changes} attribute in the Field Resource. The API will return an appropriate error if the field doesn't support historical tracking.
*/
export class FieldValueChanges {
/** @hidden */
constructor(axios) {
Object.defineProperty(this, "axios", {
enumerable: true,
configurable: true,
writable: true,
value: axios
});
}
/**
* TODO(@joscha): transform DateTime values to Date objects and then change type {@link ValueRaw} to {@link Value}
*/
static transformFieldValueChange(fieldValueChange) {
return {
...fieldValueChange,
changed_at: new Date(fieldValueChange.changed_at),
};
}
/**
* Returns all field values changes attached to a specific field.
* Field value changes can be filtered by `action_type`, person, organization, opportunity or `list_entry` by passing in the appropriate parameter.
*/
async all(params) {
const response = await this.axios.get(fieldValueChangesUrl(), {
params,
transformResponse: [
...defaultTransformers(),
(json) => {
return json.map(FieldValueChanges.transformFieldValueChange);
},
],
});
return response.data;
}
}