<commit_before>"use strict";

import endpoint from "./endpoint";

/**
 * Abstract representation of a project.
 */
export default class ProjectContextEvents {

  /**
   * Constructor.
   *
   * @param  {Tenant}  tenant     The tenant instance.
   * @param  {Project} project    The project instance.
   * @param  {String}  contextId  The context id.
   */
  constructor(tenant, project, contextId) {

    /**
     * The tenant.
     * @type {Tenant}
     */
    this.tenant = tenant;

    /**
     * The project.
     * @type {Project}
     */
    this.project = project;

    /**
     * The context.
     * @type {String}
     */
    this.contextId = contextId;

    /**
     * Construct the event source to start consuming events straight away.
     * @type {EventSource}
     */
    this.eventSource = new EventSource(endpoint("projectContextEvents", this.project.projectId, this.contextId));
  }

  /**
   * Listen to the specified event.
   * @param {ProjectContextEvent} event to listen on.
   * @param {ProjectContextEvents.eventCallback} listener
   */
  on(event, listener) {
    this.eventSource.addEventListener(event.value, listener);
  }

  /**
   * Closes the event source from the client.
   */
  close() {
    this.eventSource.close();
  }

  /**
   * Callback to handle the SSE event.
   * @callback ProjectContextEvents~eventCallback
   * @param {Object} event.
   */
}
<commit_msg>Added required parameters for CORS Event source calls.<commit_after>"use strict";

import endpoint from "./endpoint";

/**
 * Abstract representation of a project.
 */
export default class ProjectContextEvents {

  /**
   * Constructor.
   *
   * @param  {Tenant}  tenant     The tenant instance.
   * @param  {Project} project    The project instance.
   * @param  {String}  contextId  The context id.
   */
  constructor(tenant, project, contextId) {

    /**
     * The tenant.
     * @type {Tenant}
     */
    this.tenant = tenant;

    /**
     * The project.
     * @type {Project}
     */
    this.project = project;

    /**
     * The context.
     * @type {String}
     */
    this.contextId = contextId;

    /**
     * The event source of context updates
     *
     * The remote part of the url has to be explicitly appended, otherwise the event source will be creates on the same origin.
     *
     * @type {EventSource}
     * */
    this.eventSource = new EventSource(this.tenant.client.remote + endpoint("projectContextEvents", this.project.projectId, this.contextId), { withCredentials: true } );
  }

  /**
   * Listen to the specified event.
   * @param {ProjectContextEvent} event to listen on.
   * @param {ProjectContextEvents.eventCallback} listener
   */
  on(event, listener) {
    this.eventSource.addEventListener(event.value, listener, false);
  }

  /**
   * Closes the event source from the client.
   */
  close() {
    this.eventSource.close();
  }

  /**
   * Callback to handle the SSE event.
   * @callback ProjectContextEvents~eventCallback
   * @param {Object} event.
   */
}

{'fraction_non_alphanumeric': 0.12168435013262599, 'fraction_numerical': 0.0, 'mean_word_length': 2.5122235157159487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7633798', 'n_tokens_mistral': 897, 'n_tokens_neox': 886, 'n_words': 249}