Skip to content

Commit

Permalink
feat: qlik api updates (#92)
Browse files Browse the repository at this point in the history
Co-authored-by: qlikossbuild <[email protected]>
  • Loading branch information
qlikossbuild and qlikossbuild authored Oct 3, 2024
1 parent b52b748 commit 0af5f98
Show file tree
Hide file tree
Showing 78 changed files with 275 additions and 148 deletions.
2 changes: 1 addition & 1 deletion api-keys.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { A as ApiCallOptions } from './global.types--37uwGji.js';
import { A as ApiCallOptions } from './global.types-qsBNouXJ.js';
import './auth-types-PkN9CAF_.js';

type ApiKey = {
Expand Down
4 changes: 2 additions & 2 deletions api-keys.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
clearApiCache,
invokeFetch
} from "./chunks/DTGUILK5.js";
import "./chunks/2OQLWLWE.js";
} from "./chunks/YPJSS6I3.js";
import "./chunks/Q6IKFQRW.js";
import "./chunks/2ZQ3ZX7F.js";

// src/public/rest/api-keys.ts
Expand Down
2 changes: 1 addition & 1 deletion apps.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { A as ApiCallOptions, D as DownloadableBlob } from './global.types--37uwGji.js';
import { A as ApiCallOptions, D as DownloadableBlob } from './global.types-qsBNouXJ.js';
import './auth-types-PkN9CAF_.js';

type Analysis = "breakdown" | "changePoint" | "comparison" | "contribution" | "correlation" | "fact" | "mutualInfo" | "rank" | "spike" | "trend" | "values";
Expand Down
4 changes: 2 additions & 2 deletions apps.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
clearApiCache,
invokeFetch
} from "./chunks/DTGUILK5.js";
import "./chunks/2OQLWLWE.js";
} from "./chunks/YPJSS6I3.js";
import "./chunks/Q6IKFQRW.js";
import "./chunks/2ZQ3ZX7F.js";

// src/public/rest/apps.ts
Expand Down
2 changes: 1 addition & 1 deletion audits.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { A as ApiCallOptions } from './global.types--37uwGji.js';
import { A as ApiCallOptions } from './global.types-qsBNouXJ.js';
import './auth-types-PkN9CAF_.js';

type ErrorResponse = {
Expand Down
4 changes: 2 additions & 2 deletions audits.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
clearApiCache,
invokeFetch
} from "./chunks/DTGUILK5.js";
import "./chunks/2OQLWLWE.js";
} from "./chunks/YPJSS6I3.js";
import "./chunks/Q6IKFQRW.js";
import "./chunks/2ZQ3ZX7F.js";

// src/public/rest/audits.ts
Expand Down
4 changes: 2 additions & 2 deletions auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
logout,
registerAuthModule,
setDefaultHostConfig
} from "./chunks/JCJIPO2A.js";
import "./chunks/2OQLWLWE.js";
} from "./chunks/REIKX5AQ.js";
import "./chunks/Q6IKFQRW.js";
export {
auth_default as default,
getAccessToken,
Expand Down
2 changes: 1 addition & 1 deletion automations.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { A as ApiCallOptions } from './global.types--37uwGji.js';
import { A as ApiCallOptions } from './global.types-qsBNouXJ.js';
import './auth-types-PkN9CAF_.js';

type AutomationDetailRequestObject = {
Expand Down
4 changes: 2 additions & 2 deletions automations.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
clearApiCache,
invokeFetch
} from "./chunks/DTGUILK5.js";
import "./chunks/2OQLWLWE.js";
} from "./chunks/YPJSS6I3.js";
import "./chunks/Q6IKFQRW.js";
import "./chunks/2ZQ3ZX7F.js";

// src/public/rest/automations.ts
Expand Down
2 changes: 1 addition & 1 deletion brands.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { A as ApiCallOptions, D as DownloadableBlob } from './global.types--37uwGji.js';
import { A as ApiCallOptions, D as DownloadableBlob } from './global.types-qsBNouXJ.js';
import './auth-types-PkN9CAF_.js';

/**
Expand Down
4 changes: 2 additions & 2 deletions brands.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
clearApiCache,
invokeFetch
} from "./chunks/DTGUILK5.js";
import "./chunks/2OQLWLWE.js";
} from "./chunks/YPJSS6I3.js";
import "./chunks/Q6IKFQRW.js";
import "./chunks/2ZQ3ZX7F.js";

// src/public/rest/brands.ts
Expand Down
18 changes: 12 additions & 6 deletions chunks/4M3Q6QY3.js → chunks/64K3GSMQ.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
invokeFetch,
isWindows,
toValidWebsocketLocationUrl
} from "./BUSRKHDX.js";
} from "./OEVNZ5IQ.js";
import "./7RHSSS4W.js";
import {
isBrowser
} from "./2ZQ3ZX7F.js";
Expand Down Expand Up @@ -86,13 +87,17 @@ function toGlobalAppSessionId({
identity,
hostConfig,
withoutData,
useReloadEngine
useReloadEngine,
ttlSeconds
}) {
const locationUrl = toValidWebsocketLocationUrl(hostConfig);
let url = `${locationUrl}/${appId}`;
if (identity) {
url += `/${identity}`;
}
if (ttlSeconds !== void 0 && ttlSeconds >= 0) {
url += `/ttl/${ttlSeconds}`;
}
if (useReloadEngine) {
url += "/useReloadEngine";
}
Expand Down Expand Up @@ -145,7 +150,7 @@ function listenForWindowsAuthenticationInformation(session) {
return authSuggestedInWebsocket;
}
async function createAndSetupEnigmaSession(props, canRetry) {
const { createEnigmaSession } = await import("./3FHEUGST.js");
const { createEnigmaSession } = await import("./IDZSONBN.js");
const session = await createEnigmaSession(props);
setupSessionListeners(session, props);
let global;
Expand Down Expand Up @@ -566,14 +571,15 @@ function getExternalSession(externalApp, appSessionProps) {
}

// src/qix/qix-functions.ts
async function createSessionApp() {
async function createSessionApp(ttlSeconds) {
let sharedSession;
if ((await getPlatform()).isCloud) {
sharedSession = await getOrCreateSharedSession({ appId: `SessionApp_${Date.now()}` });
sharedSession = await getOrCreateSharedSession({ appId: `SessionApp_${Date.now()}`, ttlSeconds });
} else {
sharedSession = await getOrCreateSharedSession({
appId: `%3Ftransient%3D/identity/${Date.now()}`,
useSessionApp: true
useSessionApp: true,
ttlSeconds
});
}
let alreadyClosed = false;
Expand Down
Empty file added chunks/7RHSSS4W.js
Empty file.
3 changes: 2 additions & 1 deletion chunks/GVE5ABSG.js → chunks/GZRY5VHW.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
invokeFetch,
invoke_fetch_default,
parseFetchResponse
} from "./BUSRKHDX.js";
} from "./OEVNZ5IQ.js";
import "./7RHSSS4W.js";
import "./2ZQ3ZX7F.js";
export {
EncodingError,
Expand Down
9 changes: 6 additions & 3 deletions chunks/3FHEUGST.js → chunks/IDZSONBN.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
getRestCallAuthParams,
getWebSocketAuthParams,
toValidWebsocketLocationUrl
} from "./BUSRKHDX.js";
} from "./OEVNZ5IQ.js";
import "./7RHSSS4W.js";
import {
isBrowser,
isNode
Expand Down Expand Up @@ -10366,10 +10367,12 @@ async function createEnigmaSession({
appId,
identity,
hostConfig,
useReloadEngine = false
useReloadEngine = false,
ttlSeconds
}) {
const locationUrl = toValidWebsocketLocationUrl(hostConfig);
const reloadUri = encodeURIComponent(`${locationUrl}/sense/app/${appId}`);
const ttlPart = ttlSeconds !== void 0 && ttlSeconds >= 0 ? `/ttl/${0}` : "";
const identityPart = identity ? `/identity/${identity}` : "";
const reloadEnginePart = useReloadEngine ? "&workloadType=interactive-reload" : "";
let csrfToken = "";
Expand All @@ -10380,7 +10383,7 @@ async function createEnigmaSession({
}
}
const csrfPart = csrfToken ? `&qlik-csrf-token=${csrfToken}` : "";
let url = `${locationUrl}/app/${appId}${identityPart}?reloadUri=${reloadUri}${reloadEnginePart}${csrfPart}`.replace(
let url = `${locationUrl}/app/${appId}${identityPart}${ttlPart}?reloadUri=${reloadUri}${reloadEnginePart}${csrfPart}`.replace(
/^http/,
"ws"
);
Expand Down
100 changes: 98 additions & 2 deletions chunks/BUSRKHDX.js → chunks/OEVNZ5IQ.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,22 @@ function clearStoredAnonymousTokens(hostConfig) {
}

// src/auth/internal/default-auth-modules/oauth/oauth-utils.ts
function toPerformInteractiveLoginFunction(performInteractiveLogin) {
if (typeof performInteractiveLogin === "string") {
const fn = lookupInteractiveLoginFn(performInteractiveLogin);
if (!fn) {
throw new Error(`No such function: ${performInteractiveLogin}`);
}
return fn;
}
return performInteractiveLogin;
}
function lookupGetAccessFn(getAccessToken2) {
return globalThis[getAccessToken2];
}
function lookupInteractiveLoginFn(name) {
return globalThis[name];
}
function handlePossibleErrors(data) {
if (data.errors) {
throw new AuthorizationError(data.errors);
Expand Down Expand Up @@ -598,6 +611,21 @@ async function sha256(message) {
const hashBase64 = byteArrayToBase64(hashArray);
return hashBase64.replaceAll(/\+/g, "-").replaceAll(/\//g, "_").replace(/=+$/, "");
}
async function createInteractiveLoginUrl(hostConfig, redirectUri, state, verifier) {
const clientId = hostConfig.clientId || "";
const locationUrl = toValidLocationUrl(hostConfig);
const codeChallenge = await sha256(verifier);
const queryParams = {
response_type: "code",
client_id: clientId,
redirect_uri: redirectUri,
scope: hostConfig.scope || "user_default",
state,
code_challenge: codeChallenge,
code_challenge_method: "S256"
};
return `${locationUrl}/oauth/authorize?${toQueryString(queryParams)}`;
}
async function startFullPageLoginFlow(hostConfig) {
const clientId = hostConfig.clientId || "";
const locationUrl = toValidLocationUrl(hostConfig);
Expand Down Expand Up @@ -773,6 +801,39 @@ async function getOAuthTokensForBrowser(hostConfig) {
refreshToken: void 0,
errors: void 0
};
} catch (error) {
return errorMessageToAuthData("Could not fetch access token using custom function");
}
}
if (hostConfig.performInteractiveLogin) {
let usedRedirectUri;
try {
const verifier2 = generateRandomString(128);
const originalState = generateRandomString(43);
const { code: code2, state } = extractCodeAndState(
await toPerformInteractiveLoginFunction(hostConfig.performInteractiveLogin)({
getLoginUrl: async ({ redirectUri }) => {
usedRedirectUri = redirectUri;
return createInteractiveLoginUrl(hostConfig, redirectUri, originalState, verifier2);
}
})
);
if (!usedRedirectUri) {
return errorMessageToAuthData("No redirect uri provided");
}
if (originalState !== state) {
return errorMessageToAuthData("State returned by custom interactive login function does not match original");
}
if (!code2) {
return errorMessageToAuthData("No code found in response from custom interactive login function");
}
const tokenResponse = await exchangeCodeAndVerifierForAccessTokenData(
hostConfig,
code2,
verifier2,
usedRedirectUri
);
return tokenResponse;
} catch (error) {
return {
accessToken: void 0,
Expand All @@ -781,7 +842,7 @@ async function getOAuthTokensForBrowser(hostConfig) {
{
code: "",
status: 401,
title: "Could not fetch access token using custom function",
title: "Could not perform custom interactive login",
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
detail: `${error}`
}
Expand All @@ -808,6 +869,10 @@ async function getOAuthTokensForBrowser(hostConfig) {
if (oauthTokens) {
return oauthTokens;
}
if (hostConfig.performInteractiveLogin) {
return new Promise(() => {
});
}
if (hostConfig.authRedirectUserConfirmation) {
await hostConfig.authRedirectUserConfirmation();
}
Expand Down Expand Up @@ -856,6 +921,30 @@ async function refreshAccessToken(hostConfig) {
}
}
}
function extractCodeAndState(input) {
if (typeof input === "string") {
const queryParams = new URLSearchParams(new URL(input).search);
return {
code: queryParams.get("code") || "",
state: queryParams.get("state") || ""
};
}
return input;
}
function errorMessageToAuthData(message) {
return {
accessToken: void 0,
refreshToken: void 0,
errors: [
{
code: "",
status: 401,
title: message,
detail: ""
}
]
};
}

// src/auth/internal/default-auth-modules/oauth/temporary-token.ts
async function exchangeAccessTokenForTemporaryToken(hostConfig, accessToken, purpose) {
Expand Down Expand Up @@ -1250,6 +1339,12 @@ async function handleAuthenticationError6({
};
}
if (isBrowser()) {
if (hostConfig.performInteractiveLogin) {
clearStoredOauthTokens(hostConfig);
return {
retry: true
};
}
if (hostConfig.authRedirectUserConfirmation) {
await hostConfig.authRedirectUserConfirmation();
}
Expand Down Expand Up @@ -1279,7 +1374,8 @@ var oauth_default = {
"subject",
"userId",
"noCache",
"getAccessToken"
"getAccessToken",
"performInteractiveLogin"
]
})
};
Expand Down
6 changes: 3 additions & 3 deletions chunks/2OQLWLWE.js → chunks/Q6IKFQRW.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// src/public/public-runtime-modules.ts
function getAuthRuntimeModule(hostConfig) {
const isNode = !!globalThis.process?.argv;
return isNode ? import("./LVRC5AWE.js") : import("./EUWNVVK5.js").then(
return isNode ? import("./SEBN4KFZ.js") : import("./EUWNVVK5.js").then(
(mod) => mod.importRuntimeModule("auth@v1", hostConfig)
);
}
async function getQixRuntimeModule(hostConfig) {
await getAuthRuntimeModule(hostConfig);
const isNode = !!globalThis.process?.argv;
return isNode ? import("./4M3Q6QY3.js") : import("./EUWNVVK5.js").then(
return isNode ? import("./64K3GSMQ.js") : import("./EUWNVVK5.js").then(
(mod) => mod.importRuntimeModule("qix@v1", hostConfig)
);
}
async function getInvokeFetchRuntimeModule(hostConfig) {
await getAuthRuntimeModule(hostConfig);
const isNode = !!globalThis.process?.argv;
return isNode ? import("./GVE5ABSG.js") : import("./EUWNVVK5.js").then(
return isNode ? import("./GZRY5VHW.js") : import("./EUWNVVK5.js").then(
(mod) => mod.importRuntimeModule("invoke-fetch@v1", hostConfig)
);
}
Expand Down
2 changes: 1 addition & 1 deletion chunks/JCJIPO2A.js → chunks/REIKX5AQ.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
getAuthRuntimeModule
} from "./2OQLWLWE.js";
} from "./Q6IKFQRW.js";

// src/public/auth.ts
function registerAuthModule(name, authModule) {
Expand Down
2 changes: 1 addition & 1 deletion chunks/YQLW56LG.js → chunks/S6NFN6RR.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
getQixRuntimeModule
} from "./2OQLWLWE.js";
} from "./Q6IKFQRW.js";

// src/public/qix.ts
function openAppSession(appSessionProps) {
Expand Down
Loading

0 comments on commit 0af5f98

Please sign in to comment.