{"size": 1333, "ext": "js", "max_stars_repo_path": "qlik-saas/tags/1.0.5/trunk/js/iframe-sheet.js", "max_stars_repo_name": "ouadie-limouni/qlik-saas-wordpress-plugin", "max_stars_repo_stars_event_min_datetime": "2021-11-10T14:50:16.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-11T12:57:24.000Z", "max_issues_repo_path": "qlik-saas/tags/1.0.5/trunk/js/iframe-sheet.js", "max_issues_repo_name": "ouadie-limouni/qlik-saas-wordpress-plugin", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "qlik-saas/tags/1.0.5/trunk/js/iframe-sheet.js", "max_forks_repo_name": "ouadie-limouni/qlik-saas-wordpress-plugin", "max_forks_repo_forks_event_min_datetime": "2021-12-17T21:49:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-17T21:49:17.000Z"}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 33.325, "max_line_length": 187, "alphanum_fraction": 0.6571642911}
const checkStatus = async () => {
  const response = await fetch(`https://${settings.host}/api/v1/csrf-token`, {
    credentials: "include",
    headers: { "qlik-web-integration-id": settings.webIntegrationID },
  });
  if (response.status === 401) {
    await connect();
  }
}

const connect = async () => {
  await fetch(`https://${settings.host}/login/jwt-session?qlik-web-integration-id=${settings.webIntegrationID}`, {
    method: 'POST',
    credentials: 'include',
    mode: 'cors',
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${settings.token}`,
      'Qlik-Web-Integration-ID':settings.webIntegrationID,
    },
    rejectUnauthorized: false,
  });
};

const init = async () => {
  try {
    await checkStatus();
    const identity = `${Date.now().toString()}_ANON`;
    const iframe = document.createElement('iframe');
    iframe.src = `https://${settings.host}/single?appid=${settings.appID}&sheet=${settings.sheetID}&opt=currsel&qlik-web-integration-id=${settings.webIntegrationID}&identity=${identity}`;
    iframe.setAttribute('onload', `this.width=${settings.width};this.height=${settings.height};`);
    const parentNode = document.querySelector(`#qs_sheet_${settings.appID}`);
    parentNode.appendChild(iframe);
  } catch (error) {
    console.error(error);
  }
};

init();
