platform-helpers/trace-record.js

/**
 * A representation of a Tealium Trace, available inside tests via these methods:
 *  - [traceHelper.getTraceInfo]{@link module:traceHelper.getTraceInfo}
 *  - [traceHelper.endVisitAndGetTraceInfo]{@link module:traceHelper.endVisitAndGetTraceInfo}
 *
 * A lookup of some key information from the CDH profile.
 *
 * @type {object}
 * @property {object} visitorAttributes CDH Visit and Visitor Attributes, including badges. Object keys are attribute IDs.
 * @property {object} eventAttributes CDH Event Attributes. Object keys are incoming event-level attributes, from the actual payload.
 * @property {object} audiences Audience information. Object keys are the audience ID, including account and profile
 * @property {object} eventSpecs Information about Event Specs, useful for checking validity
 * @hideconstructor
 * @example
 * {
 *   "visitorAttributes": {
 *     "34": {
 *       "audienceDBEnabled": false,
 *       "context": "Visitor",
 *       "createdByPlay": [],
 *       "deleted": true,
 *       "description": "Visits per browser type",
 *       "duplicateAttributes": [],
 *       "editable": true,
 *       "eventDBEnabled": true,
 *       "eventKey": "",
 *       "hidden": true,
 *       "id": 34,
 *       "name": "Visits per browser type",
 *       "preloaded": true,
 *       "refers": 33,
 *       "transformationIds": [
 *         22
 *       ],
 *       "type": "visitor_metric_set",
 *       "utuiDuplicates": []
 *     },
 *     "39": {
 *       "audienceDBEnabled": false,
 *       "context": "Current Visit",
 *       "createdByPlay": [],
 *       "deleted": true,
 *       "description": "The type of device being used by the visitor",
 *       "duplicateAttributes": [],
 *       "editable": true,
 *       "eventDBEnabled": true,
 *       "eventKey": "",
 *       "hidden": true,
 *       "id": 39,
 *       "name": "Device",
 *       "preloaded": true,
 *       "refers": 0,
 *       "transformationIds": [],
 *       "type": "visitor_property",
 *       "utuiDuplicates": []
 *     }
 *   },
 *   "eventAttributes": {
 *     "useragent": {
 *       "name": "User Agent"
 *     },
 *     "tealium_environment": {
 *       "name": "tealium_environment"
 *     }
 *   },
 *   "audiences": {
 *     "tealium-solutions_test-example_101": {
 *       "createdByPlay": [],
 *       "editable": true,
 *       "labelIds": [],
 *       "logic": "{\"$or\":[{\"$and\":[{\"baseOperator\":null,\"operator\":\"greater_than_or_equal_to\",\"operand1\":\"metrics.5010\",\"operand2\":40}]}]}",
 *       "name": "Counter at least 40",
 *       "perspective": "badges",
 *       "visitorRetentionDays": 0
 *     },
 *     "tealium-solutions_test-example_102": {
 *       "createdByPlay": [],
 *       "editable": true,
 *       "labelIds": [],
 *       "logic": "{\"$or\":[{\"$and\":[{\"baseOperator\":null,\"operator\":\"less_than\",\"operand1\":\"metrics.5010\",\"operand2\":0}]}]}",
 *       "name": "Counter less than 0",
 *       "perspective": "badges",
 *       "visitorRetentionDays": 0
 *     }
 *   },
 *   "eventSpecs": {
 *     "update-random-to-ensure-freshness": {
 *       "id": "ae192ebc-48b4-408e-872e-fe96f7d957f6",
 *       "tealiumEvent": "update-random-to-ensure-freshness",
 *       "name": "",
 *       "notes": "",
 *       "creationDate": "2020-05-28T11:10:46.448Z",
 *       "createdBy": null,
 *       "updatedDate": "2020-05-28T11:11:10.625Z",
 *       "updatedBy": "caleb.jaquith@tealium.com",
 *       "labelIds": [],
 *       "eventAttributes": [{
 *           "attribute": "current_visit.last_event.data.udo.tealium_random",
 *           "example": null,
 *           "required": true
 *         },
 *         {
 *           "attribute": "current_visit.last_event.data.udo.tealium_visitor_id",
 *           "example": null,
 *           "required": true
 *         }
 *       ],
 *       "linkedFilteredStreamId": "8675f1d3-387b-4272-b479-a0c09d1e51ff",
 *       "custom": true
 *     }
 *   }
 * }
*/
class TraceRecord {
  constructor (output) {
    this.map = {};

    /**
     * The raw response from the Trace API, for debugging.
     *
     * @type {array}
     */
    this.traceJson = [];

    /**
     * Each array element is an instance of [TraceEvent]{@link module:TraceEvent}
     *
     * @type {array}
     */
    this.eventGroups = [];

    /**
     * An instance of [TraceSummary]{@link module:TraceSummary}
     *
     * @type {object}
     */
    this.summary = {};

    Object.assign(this, output);
  }
}

module.exports = TraceRecord;