@qlik/api 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api-keys.d.mts +14 -0
- package/api-keys.d.ts +14 -0
- package/api-keys.js +14 -10
- package/api-keys.mjs +6 -2
- package/apps.d.mts +479 -149
- package/apps.d.ts +479 -149
- package/apps.js +100 -42
- package/apps.mjs +60 -2
- package/audits.d.mts +12 -0
- package/audits.d.ts +12 -0
- package/audits.js +10 -9
- package/audits.mjs +3 -2
- package/auth-AWZV4DPP.js +41 -0
- package/{auth-RTFXVSSK.mjs → auth-CPBNNC7S.mjs} +4 -1
- package/auth.js +4 -3
- package/auth.mjs +3 -2
- package/automations.d.mts +36 -0
- package/automations.d.ts +36 -0
- package/automations.js +28 -21
- package/automations.mjs +9 -2
- package/brands.d.mts +45 -4
- package/brands.d.ts +45 -4
- package/brands.js +20 -15
- package/brands.mjs +7 -2
- package/{chunk-ZT4C7KCQ.js → chunk-2STFUQKQ.js} +3 -3
- package/{chunk-7REWEWCX.mjs → chunk-3SVRHJII.mjs} +3 -3
- package/{chunk-CKPJE4IA.mjs → chunk-67GJTTPV.mjs} +1 -1
- package/{chunk-M7F4JFOB.js → chunk-7RY3NO6N.js} +2 -2
- package/{chunk-NALKLKZS.mjs → chunk-CYRLVHU3.mjs} +316 -53
- package/{chunk-RMKP2BDX.js → chunk-D52VW5UN.js} +318 -55
- package/{chunk-GUQBHY3H.mjs → chunk-GNWU6SP2.mjs} +1 -1
- package/{chunk-QN23TPIE.js → chunk-GV5SRHY2.js} +4 -4
- package/{chunk-OULT3V2U.js → chunk-JNGURO23.js} +3 -3
- package/chunk-P57PW2II.js +11 -0
- package/{chunk-3YE7EI7I.mjs → chunk-TE7XMBT5.mjs} +1 -1
- package/chunk-ZFXKCRJC.mjs +11 -0
- package/collections.d.mts +51 -17
- package/collections.d.ts +51 -17
- package/collections.js +28 -14
- package/collections.mjs +16 -2
- package/csp-origins.d.mts +16 -1
- package/csp-origins.d.ts +16 -1
- package/csp-origins.js +12 -9
- package/csp-origins.mjs +5 -2
- package/data-assets.d.mts +10 -0
- package/data-assets.d.ts +10 -0
- package/data-assets.js +13 -8
- package/data-assets.mjs +7 -2
- package/data-connections.d.mts +18 -0
- package/data-connections.d.ts +18 -0
- package/data-connections.js +19 -12
- package/data-connections.mjs +9 -2
- package/data-credentials.d.mts +8 -0
- package/data-credentials.d.ts +8 -0
- package/data-credentials.js +10 -7
- package/data-credentials.mjs +5 -2
- package/data-files.d.mts +98 -13
- package/data-files.d.ts +98 -13
- package/data-files.js +22 -15
- package/data-files.mjs +9 -2
- package/{enigma-session-VPPJMBEM.js → enigma-session-XPXDQAIV.js} +5 -4
- package/{enigma-session-HGXKZJVO.mjs → enigma-session-ZH6MYA54.mjs} +2 -1
- package/{esm-RX7B2TUN.js → esm-3VXX2GKL.js} +3 -1
- package/{esm-M5ZBFTVD.mjs → esm-OY4XVIJB.mjs} +3 -1
- package/extensions.d.mts +26 -2
- package/extensions.d.ts +26 -2
- package/extensions.js +13 -10
- package/extensions.mjs +5 -2
- package/glossaries.d.mts +55 -20
- package/glossaries.d.ts +55 -20
- package/glossaries.js +39 -27
- package/glossaries.mjs +14 -2
- package/groups.d.mts +16 -0
- package/groups.d.ts +16 -0
- package/groups.js +16 -11
- package/groups.mjs +7 -2
- package/identity-providers.d.mts +16 -0
- package/identity-providers.d.ts +16 -0
- package/identity-providers.js +14 -11
- package/identity-providers.mjs +5 -2
- package/index.js +135 -101
- package/index.mjs +131 -97
- package/{invoke-fetch-IMO4AMA3.mjs → invoke-fetch-3WZWAAZH.mjs} +4 -1
- package/invoke-fetch-UNTAUR7O.js +17 -0
- package/items.d.mts +6 -6
- package/items.d.ts +6 -6
- package/items.js +14 -11
- package/items.mjs +5 -2
- package/licenses.d.mts +18 -0
- package/licenses.d.ts +18 -0
- package/licenses.js +17 -12
- package/licenses.mjs +7 -2
- package/package.json +4 -4
- package/{qix-K22VHZRH.js → qix-UNWXPGMA.js} +9 -8
- package/{qix-57WD2ZE6.mjs → qix-ZSJ4PIK3.mjs} +3 -2
- package/qix.d.mts +1 -1
- package/qix.d.ts +1 -1
- package/qix.js +4 -3
- package/qix.mjs +3 -2
- package/quotas.d.mts +4 -0
- package/quotas.d.ts +4 -0
- package/quotas.js +6 -5
- package/quotas.mjs +3 -2
- package/reload-tasks.js +11 -8
- package/reload-tasks.mjs +5 -2
- package/reloads.d.mts +17 -10
- package/reloads.d.ts +17 -10
- package/reloads.js +9 -7
- package/reloads.mjs +4 -2
- package/roles.d.mts +4 -0
- package/roles.d.ts +4 -0
- package/roles.js +6 -5
- package/roles.mjs +3 -2
- package/spaces.d.mts +27 -4
- package/spaces.d.ts +27 -4
- package/spaces.js +21 -15
- package/spaces.mjs +8 -2
- package/temp-contents.d.mts +8 -3
- package/temp-contents.d.ts +8 -3
- package/temp-contents.js +8 -6
- package/temp-contents.mjs +4 -2
- package/tenants.d.mts +12 -0
- package/tenants.d.ts +12 -0
- package/tenants.js +14 -9
- package/tenants.mjs +7 -2
- package/themes.d.mts +26 -2
- package/themes.d.ts +26 -2
- package/themes.js +13 -10
- package/themes.mjs +5 -2
- package/transports.d.mts +12 -0
- package/transports.d.ts +12 -0
- package/transports.js +12 -9
- package/transports.mjs +5 -2
- package/users.d.mts +48 -29
- package/users.d.ts +48 -29
- package/users.js +18 -13
- package/users.mjs +7 -2
- package/web-integrations.d.mts +10 -0
- package/web-integrations.d.ts +10 -0
- package/web-integrations.js +11 -8
- package/web-integrations.mjs +5 -2
- package/web-notifications.d.mts +12 -0
- package/web-notifications.d.ts +12 -0
- package/web-notifications.js +12 -9
- package/web-notifications.mjs +5 -2
- package/webhooks.d.mts +25 -5
- package/webhooks.d.ts +25 -5
- package/webhooks.js +17 -13
- package/webhooks.mjs +6 -2
- package/auth-CSVTXOZX.js +0 -36
- package/auth-OU7OTB7Y.js +0 -38
- package/auth-TE272Q34.mjs +0 -36
- package/chunk-4ES65KO3.js +0 -57
- package/chunk-4FLMND6T.js +0 -25
- package/chunk-4OMEH5SW.mjs +0 -1337
- package/chunk-6JERR27K.js +0 -17
- package/chunk-E42WUFCK.mjs +0 -57
- package/chunk-H7SAZYEE.js +0 -21
- package/chunk-KMMWJZHM.mjs +0 -25
- package/chunk-W4J34XGA.mjs +0 -17
- package/chunk-WM7FQU2U.mjs +0 -21
- package/chunk-XASXL2NC.js +0 -1337
- package/enigma-session-4L373ALV.mjs +0 -10196
- package/enigma-session-TEB53FAF.js +0 -10196
- package/esm-4X3DKK5D.js +0 -63
- package/esm-SOWVJKOQ.mjs +0 -63
- package/invoke-fetch-7PKPQ3FD.js +0 -14
- package/invoke-fetch-MSSJAZ7K.mjs +0 -14
- package/invoke-fetch-PEI54KZO.js +0 -14
- package/qix-EU7PXRZ6.mjs +0 -573
- package/qix-RLTISYTB.js +0 -573
package/chunk-4OMEH5SW.mjs
DELETED
|
@@ -1,1337 +0,0 @@
|
|
|
1
|
-
// src/platform/platform-functions.ts
|
|
2
|
-
var getPlatform = async (options = {}) => {
|
|
3
|
-
const isNodeEnvironment = typeof window === "undefined";
|
|
4
|
-
if (isNodeEnvironment) {
|
|
5
|
-
return result({ isNodeEnv: true });
|
|
6
|
-
}
|
|
7
|
-
const { data: productInfo, status } = await getProductInfo(options);
|
|
8
|
-
if (status === 404) {
|
|
9
|
-
return result({ isUnknown: true });
|
|
10
|
-
}
|
|
11
|
-
if (!productInfo || status <= 399 && status >= 300) {
|
|
12
|
-
return result({ isQSE: true, isWindows: true });
|
|
13
|
-
}
|
|
14
|
-
const deploymentType = (productInfo.composition?.deploymentType || "").toLowerCase();
|
|
15
|
-
if (deploymentType === "qliksenseserver") {
|
|
16
|
-
return result({ isQSE: true, isWindows: true });
|
|
17
|
-
}
|
|
18
|
-
if (deploymentType === "qliksensedesktop") {
|
|
19
|
-
return result({ isQSD: true, isWindows: true });
|
|
20
|
-
}
|
|
21
|
-
if (productInfo.composition?.provider === "fedramp") {
|
|
22
|
-
return result({ isCloud: true, isQCG: true });
|
|
23
|
-
}
|
|
24
|
-
return result({ isCloud: true, isQCS: true });
|
|
25
|
-
};
|
|
26
|
-
var productInfoPromises = {};
|
|
27
|
-
function templateUrl(baseUrl) {
|
|
28
|
-
return `${baseUrl}/resources/autogenerated/product-info.json`;
|
|
29
|
-
}
|
|
30
|
-
var getProductInfo = async ({ hostConfig, noCache } = {}) => {
|
|
31
|
-
const url = toValidLocationUrl(hostConfig);
|
|
32
|
-
const completeUrl = templateUrl(url);
|
|
33
|
-
try {
|
|
34
|
-
if (!(completeUrl in productInfoPromises)) {
|
|
35
|
-
const fetchOptions = {};
|
|
36
|
-
if (globalThis.QlikMain && globalThis.QlikMain.resourceNeedsCredentials(completeUrl)) {
|
|
37
|
-
fetchOptions.credentials = "include";
|
|
38
|
-
}
|
|
39
|
-
const productInfoPromise = fetch(completeUrl, fetchOptions).then(async (res) => {
|
|
40
|
-
if (res.ok) {
|
|
41
|
-
return { data: await res.json(), status: res.status };
|
|
42
|
-
}
|
|
43
|
-
return { data: void 0, status: res.status };
|
|
44
|
-
});
|
|
45
|
-
productInfoPromises[completeUrl] = productInfoPromise;
|
|
46
|
-
}
|
|
47
|
-
const response = await productInfoPromises[completeUrl];
|
|
48
|
-
if (response.status >= 400 || !response.data) {
|
|
49
|
-
delete productInfoPromises[completeUrl];
|
|
50
|
-
}
|
|
51
|
-
return response;
|
|
52
|
-
} catch (err) {
|
|
53
|
-
delete productInfoPromises[completeUrl];
|
|
54
|
-
return { data: void 0, status: 500 };
|
|
55
|
-
} finally {
|
|
56
|
-
if (noCache) {
|
|
57
|
-
delete productInfoPromises[completeUrl];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
var result = (data) => ({
|
|
62
|
-
isNodeEnv: false,
|
|
63
|
-
isCloud: false,
|
|
64
|
-
isQCS: false,
|
|
65
|
-
isQCG: false,
|
|
66
|
-
isWindows: false,
|
|
67
|
-
isQSE: false,
|
|
68
|
-
isQSD: false,
|
|
69
|
-
isUnknown: false,
|
|
70
|
-
...data
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// src/auth/internal/default-host-config.ts
|
|
74
|
-
var defaultHostConfig = {};
|
|
75
|
-
function setDefaultHostConfig(hostConfig) {
|
|
76
|
-
defaultHostConfig = hostConfig || {};
|
|
77
|
-
}
|
|
78
|
-
function withDefaultHostConfig(hostConfig) {
|
|
79
|
-
return hostConfig || defaultHostConfig;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// src/auth/internal/auth-module-registry.ts
|
|
83
|
-
var authModules = {};
|
|
84
|
-
var ongoingAuthModuleLoading = Promise.resolve();
|
|
85
|
-
function registerAuthModule(name, authModule) {
|
|
86
|
-
authModules[name.toLowerCase()] = authModule;
|
|
87
|
-
}
|
|
88
|
-
function getRegisteredAuthModules() {
|
|
89
|
-
return Object.keys(authModules);
|
|
90
|
-
}
|
|
91
|
-
function getRegisteredAuthModule(authType) {
|
|
92
|
-
return authModules[authType.toLowerCase()];
|
|
93
|
-
}
|
|
94
|
-
async function getAuthModule(hostConfig) {
|
|
95
|
-
const hostConfigToUse = withDefaultHostConfig(hostConfig);
|
|
96
|
-
const authType = await guessAuthTypeIfMissing(hostConfigToUse);
|
|
97
|
-
if (ongoingAuthModuleLoading) {
|
|
98
|
-
await ongoingAuthModuleLoading;
|
|
99
|
-
}
|
|
100
|
-
let authModule = getRegisteredAuthModule(authType);
|
|
101
|
-
if (!authModule) {
|
|
102
|
-
ongoingAuthModuleLoading = (async () => {
|
|
103
|
-
authModule = await resolveGloballyDefinedAuthModule(authType);
|
|
104
|
-
if (authModule) {
|
|
105
|
-
registerAuthModule(authType, authModule);
|
|
106
|
-
}
|
|
107
|
-
})();
|
|
108
|
-
await ongoingAuthModuleLoading;
|
|
109
|
-
}
|
|
110
|
-
if (!authModule) {
|
|
111
|
-
throw new InvalidAuthTypeError(authType);
|
|
112
|
-
}
|
|
113
|
-
if (authModule.validateHostConfig) {
|
|
114
|
-
authModule.validateHostConfig({ authType, ...hostConfigToUse });
|
|
115
|
-
}
|
|
116
|
-
return authModule;
|
|
117
|
-
}
|
|
118
|
-
async function guessAuthTypeIfMissing(hostConfig) {
|
|
119
|
-
if (hostConfig.authType) {
|
|
120
|
-
return hostConfig.authType;
|
|
121
|
-
}
|
|
122
|
-
if (hostConfig.apiKey) {
|
|
123
|
-
return "apikey";
|
|
124
|
-
}
|
|
125
|
-
if (hostConfig.clientId) {
|
|
126
|
-
return "oauth2";
|
|
127
|
-
}
|
|
128
|
-
if (hostConfig.webIntegrationId) {
|
|
129
|
-
return "cookie";
|
|
130
|
-
}
|
|
131
|
-
if (await isWindows(hostConfig)) {
|
|
132
|
-
return "windowscookie";
|
|
133
|
-
}
|
|
134
|
-
return "cookie";
|
|
135
|
-
}
|
|
136
|
-
async function resolveGloballyDefinedAuthModule(authType) {
|
|
137
|
-
const globalWindow = globalThis;
|
|
138
|
-
const globalVariable = globalWindow[authType];
|
|
139
|
-
if (globalVariable) {
|
|
140
|
-
let potentialAuthModule;
|
|
141
|
-
if (typeof globalVariable === "function") {
|
|
142
|
-
potentialAuthModule = await globalVariable();
|
|
143
|
-
} else {
|
|
144
|
-
potentialAuthModule = globalVariable;
|
|
145
|
-
}
|
|
146
|
-
if (potentialAuthModule && potentialAuthModule.getRestCallAuthParams && potentialAuthModule.getWebSocketAuthParams && potentialAuthModule.handleAuthenticationError) {
|
|
147
|
-
return potentialAuthModule;
|
|
148
|
-
}
|
|
149
|
-
console.error("Not a valid auth module", potentialAuthModule);
|
|
150
|
-
throw new InvalidAuthTypeError(authType);
|
|
151
|
-
}
|
|
152
|
-
return Promise.resolve(void 0);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// src/auth/auth-errors.ts
|
|
156
|
-
var InvalidHostConfigError = class extends Error {
|
|
157
|
-
constructor(message) {
|
|
158
|
-
super(`Invalid host config: ${message}`);
|
|
159
|
-
this.name = "InvalidHostConfigError";
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
var UnexpectedAuthTypeError = class extends Error {
|
|
163
|
-
constructor(...expectedAuthTypes) {
|
|
164
|
-
const ors = expectedAuthTypes.map((item, index) => index === 0 ? `"${item}"` : `or "${item}"`).join(" ");
|
|
165
|
-
super(`HostConfig is not properly configured. authType is expected to be ${ors}`);
|
|
166
|
-
this.name = "UnexpectedAuthTypeError";
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
var InvalidAuthTypeError = class extends Error {
|
|
170
|
-
constructor(authType) {
|
|
171
|
-
const validAuthModules = getRegisteredAuthModules();
|
|
172
|
-
super(
|
|
173
|
-
`Not a valid auth type: ${authType}, valid auth types are; '${validAuthModules.filter((name) => name !== "QmfeEmbedFramerAuthModule").join("', '")}'`
|
|
174
|
-
);
|
|
175
|
-
this.name = "InvalidAuthTypeError";
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
// src/auth/auth-functions.ts
|
|
180
|
-
function isHostCrossOrigin(hostConfig) {
|
|
181
|
-
if (!globalThis.location?.origin) {
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
const hostConfigToUse = withDefaultHostConfig(hostConfig);
|
|
185
|
-
if (Object.keys(hostConfigToUse).length === 0) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
const locationUrl = toValidLocationUrl(hostConfigToUse);
|
|
189
|
-
return !(locationUrl === "" || locationUrl.startsWith(globalThis.location.origin));
|
|
190
|
-
}
|
|
191
|
-
async function isWindows(hostConfig) {
|
|
192
|
-
const hostConfigToUse = withDefaultHostConfig(hostConfig);
|
|
193
|
-
if (hostConfigToUse.authType === "cookie") {
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
if (hostConfigToUse.authType === "windowscookie") {
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
return (await getPlatform({ hostConfig })).isWindows;
|
|
200
|
-
}
|
|
201
|
-
function toValidLocationUrl(hostConfig) {
|
|
202
|
-
const url = withDefaultHostConfig(hostConfig)?.host;
|
|
203
|
-
let locationUrl;
|
|
204
|
-
if (!url) {
|
|
205
|
-
locationUrl = "";
|
|
206
|
-
} else if (url.toLowerCase().startsWith("https://") || url.toLowerCase().startsWith("http://")) {
|
|
207
|
-
locationUrl = url;
|
|
208
|
-
} else {
|
|
209
|
-
locationUrl = `https://${url}`;
|
|
210
|
-
}
|
|
211
|
-
while (locationUrl[locationUrl.length - 1] === "/") {
|
|
212
|
-
locationUrl = locationUrl.substring(0, locationUrl.length - 1);
|
|
213
|
-
}
|
|
214
|
-
return locationUrl;
|
|
215
|
-
}
|
|
216
|
-
function toValidEnigmaLocationUrl(hostConfig) {
|
|
217
|
-
const url = withDefaultHostConfig(hostConfig)?.host;
|
|
218
|
-
let locationUrl;
|
|
219
|
-
if (!url) {
|
|
220
|
-
locationUrl = globalThis.location.origin;
|
|
221
|
-
} else if (url.toLowerCase().startsWith("https://") || url.toLowerCase().startsWith("http://")) {
|
|
222
|
-
locationUrl = url;
|
|
223
|
-
} else {
|
|
224
|
-
locationUrl = `https://${url}`;
|
|
225
|
-
}
|
|
226
|
-
while (locationUrl[locationUrl.length - 1] === "/") {
|
|
227
|
-
locationUrl = locationUrl.substring(0, locationUrl.length - 1);
|
|
228
|
-
}
|
|
229
|
-
return locationUrl.replace(leadingHttp, "ws");
|
|
230
|
-
}
|
|
231
|
-
async function getWebSocketAuthParams(props) {
|
|
232
|
-
const hostConfigToUse = withDefaultHostConfig(props.hostConfig);
|
|
233
|
-
return (await getAuthModule(hostConfigToUse)).getWebSocketAuthParams({
|
|
234
|
-
...props,
|
|
235
|
-
hostConfig: hostConfigToUse
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
async function getWebResourceAuthParams(props) {
|
|
239
|
-
const hostConfigToUse = withDefaultHostConfig(props.hostConfig);
|
|
240
|
-
return (await getAuthModule(hostConfigToUse)).getWebResourceAuthParams?.({
|
|
241
|
-
...props,
|
|
242
|
-
hostConfig: hostConfigToUse
|
|
243
|
-
}) || { queryParams: {} };
|
|
244
|
-
}
|
|
245
|
-
async function handleAuthenticationError(props) {
|
|
246
|
-
const hostConfigToUse = withDefaultHostConfig(props.hostConfig);
|
|
247
|
-
return (await getAuthModule(hostConfigToUse)).handleAuthenticationError({
|
|
248
|
-
...props,
|
|
249
|
-
hostConfig: hostConfigToUse
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
async function getRestCallAuthParams(props) {
|
|
253
|
-
const hostConfigToUse = withDefaultHostConfig(props.hostConfig);
|
|
254
|
-
return (await getAuthModule(hostConfigToUse)).getRestCallAuthParams({
|
|
255
|
-
...props,
|
|
256
|
-
hostConfig: hostConfigToUse
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
function registerAuthModule2(name, authModule) {
|
|
260
|
-
registerAuthModule(name, authModule);
|
|
261
|
-
}
|
|
262
|
-
function setDefaultHostConfig2(hostConfig) {
|
|
263
|
-
setDefaultHostConfig(hostConfig);
|
|
264
|
-
}
|
|
265
|
-
function checkForCrossDomainRequest(hostConfig) {
|
|
266
|
-
const hostConfigToUse = withDefaultHostConfig(hostConfig);
|
|
267
|
-
if (isHostCrossOrigin(hostConfigToUse)) {
|
|
268
|
-
if (Object.keys(hostConfigToUse).length === 0) {
|
|
269
|
-
throw new InvalidHostConfigError("a host config must be provided when making a cross domain request");
|
|
270
|
-
}
|
|
271
|
-
if (!hostConfigToUse.host) {
|
|
272
|
-
throw new InvalidHostConfigError("A 'host' must be set in host config when making a cross domain request");
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
var logout = () => {
|
|
277
|
-
globalThis.loggingOut = true;
|
|
278
|
-
globalThis.location.href = "/logout";
|
|
279
|
-
};
|
|
280
|
-
var leadingHttp = /^http/;
|
|
281
|
-
|
|
282
|
-
// src/auth/internal/auth-functions.ts
|
|
283
|
-
function getCredentialsForCookieAuth(hostConfig) {
|
|
284
|
-
if (hostConfig.crossSiteCookies === false) {
|
|
285
|
-
return "same-origin";
|
|
286
|
-
}
|
|
287
|
-
if (isHostCrossOrigin(hostConfig)) {
|
|
288
|
-
return "include";
|
|
289
|
-
}
|
|
290
|
-
return "same-origin";
|
|
291
|
-
}
|
|
292
|
-
function internalValidateHostConfig(hostConfig, options) {
|
|
293
|
-
const missingRequiredProps = [];
|
|
294
|
-
for (const requiredProp of options.requiredProps) {
|
|
295
|
-
if (!hostConfig[requiredProp]) {
|
|
296
|
-
missingRequiredProps.push(requiredProp);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
if (missingRequiredProps.length > 0) {
|
|
300
|
-
throw new InvalidHostConfigError(
|
|
301
|
-
`missing required properties in host config; '${missingRequiredProps.join("', '")}'`
|
|
302
|
-
);
|
|
303
|
-
}
|
|
304
|
-
const validProps = [
|
|
305
|
-
"authType",
|
|
306
|
-
"autoRedirect",
|
|
307
|
-
"authRedirectUserConfirmation",
|
|
308
|
-
"embedRuntimeUrl",
|
|
309
|
-
"host",
|
|
310
|
-
...options.requiredProps,
|
|
311
|
-
...options.optionalProps
|
|
312
|
-
];
|
|
313
|
-
const invalidKeys = [];
|
|
314
|
-
Object.keys(hostConfig).forEach((key) => {
|
|
315
|
-
if (!validProps.some((k) => k === key)) {
|
|
316
|
-
invalidKeys.push(key);
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
if (invalidKeys.length > 0) {
|
|
320
|
-
throw new InvalidHostConfigError(`unknown properties in host config; '${invalidKeys.join("', '")}'`);
|
|
321
|
-
}
|
|
322
|
-
return true;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// src/auth/internal/default-auth-modules/apikey.ts
|
|
326
|
-
function getRestCallAuthParams2({ hostConfig }) {
|
|
327
|
-
return Promise.resolve({
|
|
328
|
-
headers: {
|
|
329
|
-
Authorization: `Bearer ${hostConfig?.apiKey}`
|
|
330
|
-
},
|
|
331
|
-
queryParams: {},
|
|
332
|
-
credentials: "omit"
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
async function getWebSocketAuthParams2() {
|
|
336
|
-
return {
|
|
337
|
-
queryParams: {
|
|
338
|
-
// accessToken: hostConfig.apiKey,
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
function handleAuthenticationError2() {
|
|
343
|
-
return Promise.resolve({});
|
|
344
|
-
}
|
|
345
|
-
var apikey_default = {
|
|
346
|
-
getRestCallAuthParams: getRestCallAuthParams2,
|
|
347
|
-
getWebSocketAuthParams: getWebSocketAuthParams2,
|
|
348
|
-
handleAuthenticationError: handleAuthenticationError2,
|
|
349
|
-
validateHostConfig: (hostConfig) => internalValidateHostConfig(hostConfig, { requiredProps: ["apiKey"], optionalProps: [] })
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
// src/http/http-functions.ts
|
|
353
|
-
var QLIK_CSRF_TOKEN = "qlik-csrf-token";
|
|
354
|
-
function clearCsrfToken(hostConfig) {
|
|
355
|
-
const locationUrl = toValidLocationUrl(hostConfig);
|
|
356
|
-
delete csrfTokens[locationUrl];
|
|
357
|
-
}
|
|
358
|
-
async function getCsrfToken(hostConfig, noCache) {
|
|
359
|
-
const locationUrl = toValidLocationUrl(hostConfig);
|
|
360
|
-
const fetchCsrfToken = async () => {
|
|
361
|
-
const res = await invokeFetch("csrf-token", {
|
|
362
|
-
method: "get",
|
|
363
|
-
pathTemplate: "/api/v1/csrf-token",
|
|
364
|
-
options: {
|
|
365
|
-
hostConfig,
|
|
366
|
-
noCache: true
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
const csrfToken = res.headers.get(QLIK_CSRF_TOKEN);
|
|
370
|
-
if (!csrfToken) {
|
|
371
|
-
return "";
|
|
372
|
-
}
|
|
373
|
-
return csrfToken;
|
|
374
|
-
};
|
|
375
|
-
if (noCache) {
|
|
376
|
-
csrfTokens[locationUrl] = fetchCsrfToken();
|
|
377
|
-
return csrfTokens[locationUrl];
|
|
378
|
-
}
|
|
379
|
-
csrfTokens[locationUrl] = csrfTokens[locationUrl] || fetchCsrfToken();
|
|
380
|
-
return csrfTokens[locationUrl];
|
|
381
|
-
}
|
|
382
|
-
var csrfTokens = {};
|
|
383
|
-
|
|
384
|
-
// src/auth/internal/default-auth-modules/cookie.ts
|
|
385
|
-
function isModifyingVerb(verb) {
|
|
386
|
-
return !(verb === "get" || verb === "GET");
|
|
387
|
-
}
|
|
388
|
-
async function getRestCallAuthParams3({
|
|
389
|
-
hostConfig,
|
|
390
|
-
method
|
|
391
|
-
}) {
|
|
392
|
-
const headers = {};
|
|
393
|
-
if (isModifyingVerb(method)) {
|
|
394
|
-
headers["qlik-csrf-token"] = await getCsrfToken(hostConfig);
|
|
395
|
-
}
|
|
396
|
-
if (hostConfig.webIntegrationId) {
|
|
397
|
-
headers["qlik-web-integration-id"] = hostConfig.webIntegrationId;
|
|
398
|
-
}
|
|
399
|
-
return { headers, queryParams: {}, credentials: getCredentialsForCookieAuth(hostConfig) };
|
|
400
|
-
}
|
|
401
|
-
async function getWebSocketAuthParams3({
|
|
402
|
-
hostConfig
|
|
403
|
-
}) {
|
|
404
|
-
const params = {
|
|
405
|
-
// Bypass the cache to get one rest call out the door that can catch a 401 since the websocket only returns a general error
|
|
406
|
-
"qlik-csrf-token": await getCsrfToken(hostConfig, true)
|
|
407
|
-
};
|
|
408
|
-
if (hostConfig.webIntegrationId) {
|
|
409
|
-
params["qlik-web-integration-id"] = hostConfig.webIntegrationId;
|
|
410
|
-
}
|
|
411
|
-
return { queryParams: params };
|
|
412
|
-
}
|
|
413
|
-
async function handleAuthenticationError3({
|
|
414
|
-
hostConfig,
|
|
415
|
-
status,
|
|
416
|
-
errorBody = {}
|
|
417
|
-
}) {
|
|
418
|
-
clearCsrfToken(hostConfig);
|
|
419
|
-
if (status === 403) {
|
|
420
|
-
return {
|
|
421
|
-
preventDefault: false,
|
|
422
|
-
// Only retry if the csrf token has expired
|
|
423
|
-
retry: errorBody?.code === "CSRF-TOKEN-2"
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
const webIntegrationParam = hostConfig.webIntegrationId ? `qlik-web-integration-id=${hostConfig?.webIntegrationId}&` : "";
|
|
427
|
-
const locationUrl = toValidLocationUrl(hostConfig);
|
|
428
|
-
if (hostConfig.authRedirectUserConfirmation) {
|
|
429
|
-
await hostConfig.authRedirectUserConfirmation();
|
|
430
|
-
}
|
|
431
|
-
globalThis.location.replace(
|
|
432
|
-
`${locationUrl}/login?${webIntegrationParam}returnto=${encodeURIComponent(globalThis.location.href)}`
|
|
433
|
-
);
|
|
434
|
-
return {
|
|
435
|
-
preventDefault: true
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
var cookie_default = {
|
|
439
|
-
getRestCallAuthParams: getRestCallAuthParams3,
|
|
440
|
-
getWebSocketAuthParams: getWebSocketAuthParams3,
|
|
441
|
-
handleAuthenticationError: handleAuthenticationError3,
|
|
442
|
-
validateHostConfig: (hostConfig) => internalValidateHostConfig(hostConfig, {
|
|
443
|
-
requiredProps: [],
|
|
444
|
-
optionalProps: ["webIntegrationId", "crossSiteCookies"]
|
|
445
|
-
})
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
// src/auth/internal/default-auth-modules/none.ts
|
|
449
|
-
function getRestCallAuthParams4() {
|
|
450
|
-
return Promise.resolve({ headers: {}, queryParams: {}, credentials: "same-origin" });
|
|
451
|
-
}
|
|
452
|
-
function getWebSocketAuthParams4() {
|
|
453
|
-
return Promise.resolve({ queryParams: {} });
|
|
454
|
-
}
|
|
455
|
-
function handleAuthenticationError4() {
|
|
456
|
-
return Promise.resolve({});
|
|
457
|
-
}
|
|
458
|
-
var none_default = {
|
|
459
|
-
getRestCallAuthParams: getRestCallAuthParams4,
|
|
460
|
-
getWebSocketAuthParams: getWebSocketAuthParams4,
|
|
461
|
-
handleAuthenticationError: handleAuthenticationError4,
|
|
462
|
-
validateHostConfig: (hostConfig) => internalValidateHostConfig(hostConfig, { requiredProps: [], optionalProps: [] })
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
// src/auth/internal/default-auth-modules/oauth/storage-helpers.ts
|
|
466
|
-
var storagePrefix = "qlik-qmfe-api";
|
|
467
|
-
var tokens = {};
|
|
468
|
-
function saveInLocalStorage(scope, name, value) {
|
|
469
|
-
localStorage.setItem(`${storagePrefix}-${scope}-${name}`, value);
|
|
470
|
-
}
|
|
471
|
-
function saveInSessionStorage(scope, name, value) {
|
|
472
|
-
sessionStorage.setItem(`${storagePrefix}-${scope}-${name}`, value);
|
|
473
|
-
}
|
|
474
|
-
function loadFromLocalStorage(scope, name) {
|
|
475
|
-
return localStorage.getItem(`${storagePrefix}-${scope}-${name}`) || void 0;
|
|
476
|
-
}
|
|
477
|
-
function loadFromSessionStorage(scope, name) {
|
|
478
|
-
return sessionStorage.getItem(`${storagePrefix}-${scope}-${name}`) || void 0;
|
|
479
|
-
}
|
|
480
|
-
function deleteFromLocalStorage(scope, name) {
|
|
481
|
-
localStorage.removeItem(`${storagePrefix}-${scope}-${name}`);
|
|
482
|
-
}
|
|
483
|
-
function deleteFromSessionStorage(scope, name) {
|
|
484
|
-
sessionStorage.removeItem(`${storagePrefix}-${scope}-${name}`);
|
|
485
|
-
}
|
|
486
|
-
function loadAndDeleteFromSessionStorage(scope, name) {
|
|
487
|
-
const id = `${storagePrefix}-${scope}-${name}`;
|
|
488
|
-
const result2 = sessionStorage.getItem(id) || void 0;
|
|
489
|
-
sessionStorage.removeItem(id);
|
|
490
|
-
return result2;
|
|
491
|
-
}
|
|
492
|
-
function loadAccessTokenFromStorage(hostConfig) {
|
|
493
|
-
if (!hostConfig.clientId) {
|
|
494
|
-
return void 0;
|
|
495
|
-
}
|
|
496
|
-
if (hostConfig.accessTokenStorage === "local") {
|
|
497
|
-
return loadFromLocalStorage(hostConfig.clientId, "access-token");
|
|
498
|
-
}
|
|
499
|
-
if (hostConfig.accessTokenStorage === "session") {
|
|
500
|
-
return loadFromSessionStorage(hostConfig.clientId, "access-token");
|
|
501
|
-
}
|
|
502
|
-
return void 0;
|
|
503
|
-
}
|
|
504
|
-
async function loadOrAcquireAccessToken(hostConfig, acquireToken) {
|
|
505
|
-
if (!hostConfig.clientId) {
|
|
506
|
-
throw new InvalidHostConfigError('A host config with authType set to "oauth2" has to also provide a clientId');
|
|
507
|
-
}
|
|
508
|
-
const storedToken = hostConfig.clientId ? tokens[hostConfig.clientId] || loadAccessTokenFromStorage(hostConfig) : void 0;
|
|
509
|
-
if (storedToken) {
|
|
510
|
-
return Promise.resolve(storedToken);
|
|
511
|
-
}
|
|
512
|
-
const token = acquireToken();
|
|
513
|
-
tokens[hostConfig.clientId] = token;
|
|
514
|
-
const awaitedToken = await token;
|
|
515
|
-
if (hostConfig.accessTokenStorage === "local" && awaitedToken) {
|
|
516
|
-
saveInLocalStorage(hostConfig.clientId, "access-token", awaitedToken);
|
|
517
|
-
} else if (hostConfig.accessTokenStorage === "session" && awaitedToken) {
|
|
518
|
-
saveInSessionStorage(hostConfig.clientId, "access-token", awaitedToken);
|
|
519
|
-
}
|
|
520
|
-
return token;
|
|
521
|
-
}
|
|
522
|
-
function clearStoredAccessToken(hostConfig) {
|
|
523
|
-
if (!hostConfig.clientId) {
|
|
524
|
-
throw new InvalidHostConfigError('A host config with authType set to "oauth2" has to also provide a clientId');
|
|
525
|
-
}
|
|
526
|
-
delete tokens[hostConfig.clientId];
|
|
527
|
-
deleteFromLocalStorage(hostConfig.clientId, "access-token");
|
|
528
|
-
deleteFromSessionStorage(hostConfig.clientId, "access-token");
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
// src/auth/internal/default-auth-modules/oauth/callback.ts
|
|
532
|
-
function handleOAuthCallback() {
|
|
533
|
-
const urlParams = new URLSearchParams(globalThis.location.search);
|
|
534
|
-
const callbackCode = urlParams.get("code") || void 0;
|
|
535
|
-
const callbackState = urlParams.get("state") || void 0;
|
|
536
|
-
if (urlParams.get("error")) {
|
|
537
|
-
const element = document.createElement("pre");
|
|
538
|
-
element.innerText = `<code>${JSON.stringify({
|
|
539
|
-
error: urlParams.get("error"),
|
|
540
|
-
error_code: urlParams.get("error_code"),
|
|
541
|
-
error_description: urlParams.get("error_description"),
|
|
542
|
-
error_detail: urlParams.get("error_detail"),
|
|
543
|
-
error_uri: urlParams.get("error_uri")
|
|
544
|
-
})}</code>`;
|
|
545
|
-
document.body.prepend(element);
|
|
546
|
-
}
|
|
547
|
-
const clientId = loadAndDeleteFromSessionStorage("", "client-in-progress");
|
|
548
|
-
if (clientId && callbackCode && callbackState) {
|
|
549
|
-
const stateFromLocalStorage = loadAndDeleteFromSessionStorage(clientId, "state");
|
|
550
|
-
const finalRedirectUri = loadAndDeleteFromSessionStorage(clientId, "href");
|
|
551
|
-
if (stateFromLocalStorage && stateFromLocalStorage === callbackState && finalRedirectUri) {
|
|
552
|
-
saveInSessionStorage(clientId, "code", callbackCode);
|
|
553
|
-
if (finalRedirectUri !== globalThis.location.href) {
|
|
554
|
-
globalThis.location.replace(finalRedirectUri);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
// src/auth/internal/default-auth-modules/oauth/oauth-utils.ts
|
|
561
|
-
function generateRandomString(targetLength) {
|
|
562
|
-
const byteArrayLength = Math.ceil(targetLength * 3 / 4);
|
|
563
|
-
const array = new Uint8Array(byteArrayLength);
|
|
564
|
-
globalThis.crypto.getRandomValues(array);
|
|
565
|
-
const base64UrlString = toBase64Url(array);
|
|
566
|
-
return base64UrlString.substring(0, targetLength);
|
|
567
|
-
}
|
|
568
|
-
function toBase64Url(uint8Array) {
|
|
569
|
-
const hashArray = Array.from(uint8Array);
|
|
570
|
-
const regularBase64 = byteArrayToBase64(hashArray);
|
|
571
|
-
return regularBase64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
572
|
-
}
|
|
573
|
-
function byteArrayToBase64(hashArray) {
|
|
574
|
-
let result2 = "";
|
|
575
|
-
if (typeof globalThis.Buffer !== "undefined") {
|
|
576
|
-
result2 = Buffer.from(hashArray).toString("base64");
|
|
577
|
-
} else if (typeof window !== "undefined" && typeof window.btoa === "function") {
|
|
578
|
-
const byteArrayToString = String.fromCharCode.apply(null, hashArray);
|
|
579
|
-
result2 = window.btoa(byteArrayToString);
|
|
580
|
-
} else {
|
|
581
|
-
throw new Error("Environment not supported");
|
|
582
|
-
}
|
|
583
|
-
return result2;
|
|
584
|
-
}
|
|
585
|
-
async function sha256(message) {
|
|
586
|
-
const msgBuffer = new TextEncoder().encode(message);
|
|
587
|
-
const hashBuffer = await globalThis.crypto.subtle.digest("SHA-256", msgBuffer);
|
|
588
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
589
|
-
const hashBase64 = byteArrayToBase64(hashArray);
|
|
590
|
-
return hashBase64.replaceAll(/\+/g, "-").replaceAll(/\//g, "_").replace(/=+$/, "");
|
|
591
|
-
}
|
|
592
|
-
function toQueryString(queryParams) {
|
|
593
|
-
const queryParamsKeys = Object.keys(queryParams);
|
|
594
|
-
queryParamsKeys.sort();
|
|
595
|
-
const query = queryParamsKeys.map((k) => `${k}=${queryParams[k]}`).join("&");
|
|
596
|
-
return query;
|
|
597
|
-
}
|
|
598
|
-
async function startFullPageLoginFlow(hostConfig) {
|
|
599
|
-
const clientId = hostConfig.clientId || "";
|
|
600
|
-
const locationUrl = toValidLocationUrl(hostConfig);
|
|
601
|
-
const verifier = generateRandomString(128);
|
|
602
|
-
const state = generateRandomString(43);
|
|
603
|
-
const codeChallenge = await sha256(verifier);
|
|
604
|
-
const redirectUri = hostConfig.redirectUri || globalThis.location.href;
|
|
605
|
-
const scopes = ["user_default"];
|
|
606
|
-
clearStoredAccessToken(hostConfig);
|
|
607
|
-
saveInSessionStorage(clientId, "state", state);
|
|
608
|
-
saveInSessionStorage(clientId, "verifier", verifier);
|
|
609
|
-
saveInSessionStorage(clientId, "href", globalThis.location.href);
|
|
610
|
-
saveInSessionStorage("", "client-in-progress", clientId);
|
|
611
|
-
const queryParams = {
|
|
612
|
-
response_type: "code",
|
|
613
|
-
client_id: clientId,
|
|
614
|
-
redirect_uri: redirectUri,
|
|
615
|
-
scope: scopes.join(" "),
|
|
616
|
-
state,
|
|
617
|
-
code_challenge: codeChallenge,
|
|
618
|
-
code_challenge_method: "S256"
|
|
619
|
-
};
|
|
620
|
-
const url = `${locationUrl}/oauth/authorize?${toQueryString(queryParams)}`;
|
|
621
|
-
globalThis.location.replace(url);
|
|
622
|
-
}
|
|
623
|
-
async function exchangeCodeAndVerifierForAccessTokenData(hostConfig, code, verifier, redirectUri) {
|
|
624
|
-
try {
|
|
625
|
-
const result2 = await fetch(`${toValidLocationUrl(hostConfig)}/oauth/token`, {
|
|
626
|
-
method: "POST",
|
|
627
|
-
credentials: "include",
|
|
628
|
-
mode: "cors",
|
|
629
|
-
headers: { "content-type": "application/json" },
|
|
630
|
-
redirect: "follow",
|
|
631
|
-
body: JSON.stringify({
|
|
632
|
-
grant_type: "authorization_code",
|
|
633
|
-
scope: hostConfig.scope || "user_default",
|
|
634
|
-
...code ? { code } : {},
|
|
635
|
-
...{ redirect_uri: redirectUri || globalThis.location.href },
|
|
636
|
-
...verifier ? { code_verifier: verifier } : {},
|
|
637
|
-
client_id: hostConfig.clientId
|
|
638
|
-
})
|
|
639
|
-
});
|
|
640
|
-
const data = await result2.json();
|
|
641
|
-
return {
|
|
642
|
-
accessToken: data.access_token,
|
|
643
|
-
refreshToken: data.refresh_token
|
|
644
|
-
};
|
|
645
|
-
} catch (err) {
|
|
646
|
-
console.error(err);
|
|
647
|
-
return new Promise(() => {
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
async function getOAuthAccessTokenInternal(hostConfig) {
|
|
652
|
-
const { clientId } = hostConfig;
|
|
653
|
-
if (!clientId) {
|
|
654
|
-
throw new InvalidHostConfigError('A host config with authType set to "oauth2" has to also provide a clientId');
|
|
655
|
-
}
|
|
656
|
-
const accessToken = await loadOrAcquireAccessToken(hostConfig, async () => {
|
|
657
|
-
const code = loadAndDeleteFromSessionStorage(clientId, "code");
|
|
658
|
-
const verifier = loadAndDeleteFromSessionStorage(clientId, "verifier");
|
|
659
|
-
if (code && verifier) {
|
|
660
|
-
const tokensResponse = await exchangeCodeAndVerifierForAccessTokenData(
|
|
661
|
-
hostConfig,
|
|
662
|
-
code,
|
|
663
|
-
verifier,
|
|
664
|
-
hostConfig.redirectUri
|
|
665
|
-
);
|
|
666
|
-
if (tokensResponse) {
|
|
667
|
-
return tokensResponse.accessToken;
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
return void 0;
|
|
671
|
-
});
|
|
672
|
-
if (accessToken) {
|
|
673
|
-
return accessToken;
|
|
674
|
-
}
|
|
675
|
-
if (hostConfig.authRedirectUserConfirmation) {
|
|
676
|
-
await hostConfig.authRedirectUserConfirmation();
|
|
677
|
-
}
|
|
678
|
-
startFullPageLoginFlow(hostConfig);
|
|
679
|
-
return new Promise(() => {
|
|
680
|
-
});
|
|
681
|
-
}
|
|
682
|
-
var lastOauthAccessTokenCall = Promise.resolve("");
|
|
683
|
-
async function getOAuthAccessToken(hostConfig) {
|
|
684
|
-
lastOauthAccessTokenCall = lastOauthAccessTokenCall.then(async () => getOAuthAccessTokenInternal(hostConfig));
|
|
685
|
-
return lastOauthAccessTokenCall;
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
// src/auth/internal/default-auth-modules/oauth/temporary-token.ts
|
|
689
|
-
async function exchangeAccessTokenForTemporaryToken(hostConfig, accessToken, purpose) {
|
|
690
|
-
const result2 = await fetch(`${toValidLocationUrl(hostConfig)}/oauth/token`, {
|
|
691
|
-
method: "POST",
|
|
692
|
-
credentials: "include",
|
|
693
|
-
mode: "cors",
|
|
694
|
-
headers: { "content-type": "application/json" },
|
|
695
|
-
redirect: "follow",
|
|
696
|
-
body: JSON.stringify({
|
|
697
|
-
subject_token: accessToken,
|
|
698
|
-
subject_token_type: "urn:ietf:params:oauth:token-type:access_token",
|
|
699
|
-
grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
|
|
700
|
-
purpose,
|
|
701
|
-
redirect_uri: globalThis.location?.href,
|
|
702
|
-
client_id: hostConfig.clientId
|
|
703
|
-
})
|
|
704
|
-
});
|
|
705
|
-
if (result2.status === 401) {
|
|
706
|
-
if (hostConfig.authRedirectUserConfirmation) {
|
|
707
|
-
await hostConfig.authRedirectUserConfirmation();
|
|
708
|
-
}
|
|
709
|
-
startFullPageLoginFlow(hostConfig);
|
|
710
|
-
return new Promise(() => {
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
|
-
const data = await result2.json();
|
|
714
|
-
return data.access_token;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
// src/auth/internal/default-auth-modules/oauth.ts
|
|
718
|
-
if (typeof window !== "undefined") {
|
|
719
|
-
handleOAuthCallback();
|
|
720
|
-
}
|
|
721
|
-
async function getRestCallAuthParams5({
|
|
722
|
-
hostConfig
|
|
723
|
-
}) {
|
|
724
|
-
return {
|
|
725
|
-
headers: {
|
|
726
|
-
Authorization: `Bearer ${await getOAuthAccessToken(hostConfig)}`
|
|
727
|
-
},
|
|
728
|
-
queryParams: {},
|
|
729
|
-
credentials: "omit"
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
async function getWebSocketAuthParams5({
|
|
733
|
-
hostConfig
|
|
734
|
-
}) {
|
|
735
|
-
const accessToken = await getOAuthAccessToken(hostConfig);
|
|
736
|
-
const websocketAccessToken = await exchangeAccessTokenForTemporaryToken(hostConfig, accessToken, "websocket");
|
|
737
|
-
return {
|
|
738
|
-
queryParams: {
|
|
739
|
-
accessToken: websocketAccessToken
|
|
740
|
-
}
|
|
741
|
-
};
|
|
742
|
-
}
|
|
743
|
-
async function getWebResourceAuthParams2({
|
|
744
|
-
hostConfig
|
|
745
|
-
}) {
|
|
746
|
-
const accessToken = await getOAuthAccessToken(hostConfig);
|
|
747
|
-
const webResourceAccessToken = await exchangeAccessTokenForTemporaryToken(hostConfig, accessToken, "webresource");
|
|
748
|
-
return {
|
|
749
|
-
queryParams: {
|
|
750
|
-
accessToken: webResourceAccessToken
|
|
751
|
-
}
|
|
752
|
-
};
|
|
753
|
-
}
|
|
754
|
-
async function handleAuthenticationError5({
|
|
755
|
-
hostConfig
|
|
756
|
-
}) {
|
|
757
|
-
if (hostConfig.authRedirectUserConfirmation) {
|
|
758
|
-
await hostConfig.authRedirectUserConfirmation();
|
|
759
|
-
}
|
|
760
|
-
startFullPageLoginFlow(hostConfig);
|
|
761
|
-
return {
|
|
762
|
-
preventDefault: true
|
|
763
|
-
};
|
|
764
|
-
}
|
|
765
|
-
var oauth_default = {
|
|
766
|
-
getRestCallAuthParams: getRestCallAuthParams5,
|
|
767
|
-
getWebSocketAuthParams: getWebSocketAuthParams5,
|
|
768
|
-
getWebResourceAuthParams: getWebResourceAuthParams2,
|
|
769
|
-
handleAuthenticationError: handleAuthenticationError5,
|
|
770
|
-
validateHostConfig: (hostConfig) => internalValidateHostConfig(hostConfig, {
|
|
771
|
-
requiredProps: ["clientId"],
|
|
772
|
-
optionalProps: ["redirectUri", "accessTokenStorage"]
|
|
773
|
-
})
|
|
774
|
-
};
|
|
775
|
-
|
|
776
|
-
// src/auth/internal/default-auth-modules/windows-cookie/xrf-keys.ts
|
|
777
|
-
var xrfKeys = {};
|
|
778
|
-
function createXrfKey() {
|
|
779
|
-
let result2 = "";
|
|
780
|
-
for (let i = 0; i < 16; i += 1) {
|
|
781
|
-
const j = Math.floor(Math.random() * 62);
|
|
782
|
-
if (j < 10) {
|
|
783
|
-
result2 += j;
|
|
784
|
-
} else if (j > 9 && j < 36) {
|
|
785
|
-
result2 += String.fromCharCode(j + 55);
|
|
786
|
-
} else {
|
|
787
|
-
result2 += String.fromCharCode(j + 61);
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
return result2;
|
|
791
|
-
}
|
|
792
|
-
function getXrfKey(hostConfig) {
|
|
793
|
-
const locationUrl = toValidLocationUrl(hostConfig);
|
|
794
|
-
xrfKeys[locationUrl] = xrfKeys[locationUrl] || createXrfKey();
|
|
795
|
-
return xrfKeys[locationUrl];
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
// src/auth/internal/default-auth-modules/windows-cookie.ts
|
|
799
|
-
function getRestCallAuthParams6({
|
|
800
|
-
hostConfig
|
|
801
|
-
}) {
|
|
802
|
-
return Promise.resolve({
|
|
803
|
-
headers: {
|
|
804
|
-
"X-Qlik-XrfKey": getXrfKey(hostConfig)
|
|
805
|
-
},
|
|
806
|
-
queryParams: {
|
|
807
|
-
xrfkey: getXrfKey(hostConfig)
|
|
808
|
-
},
|
|
809
|
-
credentials: getCredentialsForCookieAuth(hostConfig)
|
|
810
|
-
});
|
|
811
|
-
}
|
|
812
|
-
function getWebSocketAuthParams6({
|
|
813
|
-
hostConfig
|
|
814
|
-
}) {
|
|
815
|
-
return Promise.resolve({
|
|
816
|
-
queryParams: {
|
|
817
|
-
xrfkey: getXrfKey(hostConfig)
|
|
818
|
-
}
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
|
-
async function handleAuthenticationError6({
|
|
822
|
-
hostConfig
|
|
823
|
-
}) {
|
|
824
|
-
if (hostConfig.loginUri) {
|
|
825
|
-
if (hostConfig.authRedirectUserConfirmation) {
|
|
826
|
-
await hostConfig.authRedirectUserConfirmation();
|
|
827
|
-
}
|
|
828
|
-
globalThis.location.replace(
|
|
829
|
-
hostConfig.loginUri.replace("{location}", encodeURIComponent(globalThis.location.href))
|
|
830
|
-
);
|
|
831
|
-
return {
|
|
832
|
-
preventDefault: true
|
|
833
|
-
};
|
|
834
|
-
}
|
|
835
|
-
return {
|
|
836
|
-
// Do nothing, just let the error be thrown to calling code
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
var windows_cookie_default = {
|
|
840
|
-
getRestCallAuthParams: getRestCallAuthParams6,
|
|
841
|
-
getWebSocketAuthParams: getWebSocketAuthParams6,
|
|
842
|
-
handleAuthenticationError: handleAuthenticationError6,
|
|
843
|
-
validateHostConfig: (hostConfig) => internalValidateHostConfig(hostConfig, {
|
|
844
|
-
requiredProps: [],
|
|
845
|
-
optionalProps: ["loginUri", "crossSiteCookies"]
|
|
846
|
-
})
|
|
847
|
-
};
|
|
848
|
-
|
|
849
|
-
// src/auth/auth.ts
|
|
850
|
-
globalThis.loggingOut = false;
|
|
851
|
-
var authModulesRegistered = false;
|
|
852
|
-
function registerDefaultAuthModules() {
|
|
853
|
-
if (!authModulesRegistered) {
|
|
854
|
-
registerAuthModule("apikey", apikey_default);
|
|
855
|
-
registerAuthModule("cookie", cookie_default);
|
|
856
|
-
registerAuthModule("none", none_default);
|
|
857
|
-
registerAuthModule("oauth2", oauth_default);
|
|
858
|
-
registerAuthModule("windowscookie", windows_cookie_default);
|
|
859
|
-
authModulesRegistered = true;
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
registerDefaultAuthModules();
|
|
863
|
-
var auth = {
|
|
864
|
-
logout,
|
|
865
|
-
registerAuthModule,
|
|
866
|
-
setDefaultHostConfig: setDefaultHostConfig2,
|
|
867
|
-
getRestCallAuthParams,
|
|
868
|
-
getWebSocketAuthParams,
|
|
869
|
-
getWebResourceAuthParams,
|
|
870
|
-
handleAuthenticationError,
|
|
871
|
-
toValidLocationUrl,
|
|
872
|
-
toValidEnigmaLocationUrl,
|
|
873
|
-
isWindows,
|
|
874
|
-
isHostCrossOrigin
|
|
875
|
-
};
|
|
876
|
-
var auth_default = auth;
|
|
877
|
-
|
|
878
|
-
// src/invoke-fetch/internal/invoke-fetch-helpers.ts
|
|
879
|
-
function encodeQueryParams(query) {
|
|
880
|
-
if (query) {
|
|
881
|
-
return Object.entries(query).map((kv) => {
|
|
882
|
-
const [, value] = kv;
|
|
883
|
-
if (value === void 0) {
|
|
884
|
-
return void 0;
|
|
885
|
-
}
|
|
886
|
-
return kv.map(
|
|
887
|
-
(val) => (
|
|
888
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
889
|
-
encodeURIComponent(val)
|
|
890
|
-
)
|
|
891
|
-
).join("=");
|
|
892
|
-
}).filter(Boolean).join("&");
|
|
893
|
-
}
|
|
894
|
-
return "";
|
|
895
|
-
}
|
|
896
|
-
function applyPathVariables(pathTemplate, pathVariables) {
|
|
897
|
-
let result2 = pathTemplate;
|
|
898
|
-
if (pathVariables) {
|
|
899
|
-
Object.keys(pathVariables).forEach((key) => {
|
|
900
|
-
result2 = result2.replace(`{${key}}`, pathVariables[key]);
|
|
901
|
-
});
|
|
902
|
-
}
|
|
903
|
-
return result2;
|
|
904
|
-
}
|
|
905
|
-
function toCacheKey(url, query, headers) {
|
|
906
|
-
let cacheKey = url;
|
|
907
|
-
if (query !== "") {
|
|
908
|
-
cacheKey = cacheKey.concat(`?${query}`);
|
|
909
|
-
}
|
|
910
|
-
if (headers) {
|
|
911
|
-
cacheKey = cacheKey.concat(`+headers=${JSON.stringify(headers)}`);
|
|
912
|
-
}
|
|
913
|
-
return cacheKey;
|
|
914
|
-
}
|
|
915
|
-
function toCompleteUrl(url, query) {
|
|
916
|
-
if (query !== "") {
|
|
917
|
-
return `${url}?${query}`;
|
|
918
|
-
}
|
|
919
|
-
return url;
|
|
920
|
-
}
|
|
921
|
-
function shouldUseCachedResult(options, cacheEntry, defaultMaxCacheTime) {
|
|
922
|
-
if (!cacheEntry || typeof cacheEntry.value === void 0) {
|
|
923
|
-
return false;
|
|
924
|
-
}
|
|
925
|
-
if (options?.noCache) {
|
|
926
|
-
return false;
|
|
927
|
-
}
|
|
928
|
-
if (options?.useCacheIfAfter) {
|
|
929
|
-
return options.useCacheIfAfter.getTime() <= cacheEntry.lastPulled;
|
|
930
|
-
}
|
|
931
|
-
const age = Date.now() - cacheEntry.lastPulled;
|
|
932
|
-
if (options?.maxCacheAge) {
|
|
933
|
-
return age <= options?.maxCacheAge;
|
|
934
|
-
}
|
|
935
|
-
return age < defaultMaxCacheTime;
|
|
936
|
-
}
|
|
937
|
-
var shouldPopulateCache = (method) => method === "get" || method === "GET";
|
|
938
|
-
function clone(value) {
|
|
939
|
-
return JSON.parse(JSON.stringify(value));
|
|
940
|
-
}
|
|
941
|
-
function isModifyingVerb2(verb) {
|
|
942
|
-
return !(verb === "get" || verb === "GET");
|
|
943
|
-
}
|
|
944
|
-
function cacheKeyToUrl(cachedUrl) {
|
|
945
|
-
const queryIdx = cachedUrl.indexOf("?");
|
|
946
|
-
if (queryIdx >= 0) {
|
|
947
|
-
return cachedUrl.substring(0, queryIdx);
|
|
948
|
-
}
|
|
949
|
-
const headersIdx = cachedUrl.indexOf("+headers=");
|
|
950
|
-
if (headersIdx >= 0) {
|
|
951
|
-
return cachedUrl.substring(0, headersIdx);
|
|
952
|
-
}
|
|
953
|
-
return cachedUrl;
|
|
954
|
-
}
|
|
955
|
-
function clearRelatedCacheEntries(cache2, cacheKey) {
|
|
956
|
-
const modifyingUrl = cacheKeyToUrl(cacheKey);
|
|
957
|
-
for (const existingCacheKey in cache2) {
|
|
958
|
-
const cleanUrl = cacheKeyToUrl(existingCacheKey);
|
|
959
|
-
if (
|
|
960
|
-
// Either up or down the path...
|
|
961
|
-
modifyingUrl.startsWith(cleanUrl) || cleanUrl.startsWith(modifyingUrl)
|
|
962
|
-
) {
|
|
963
|
-
delete cache2[existingCacheKey];
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
function cloneResultPromise(value) {
|
|
968
|
-
return value.then((resp) => {
|
|
969
|
-
const result2 = {
|
|
970
|
-
data: clone(resp.data),
|
|
971
|
-
headers: resp.headers,
|
|
972
|
-
status: resp.status
|
|
973
|
-
};
|
|
974
|
-
if (resp.next) {
|
|
975
|
-
result2.next = resp.next;
|
|
976
|
-
}
|
|
977
|
-
if (resp.prev) {
|
|
978
|
-
result2.prev = resp.prev;
|
|
979
|
-
}
|
|
980
|
-
return result2;
|
|
981
|
-
});
|
|
982
|
-
}
|
|
983
|
-
function clearCacheOnError(cacheEntry, cacheKey, value) {
|
|
984
|
-
return value.catch((error) => {
|
|
985
|
-
delete cacheEntry[cacheKey];
|
|
986
|
-
return Promise.reject(error);
|
|
987
|
-
});
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
// src/invoke-fetch/internal/invoke-fetch-methods.ts
|
|
991
|
-
var defaultCacheTime = 1e3 * 60 * 10;
|
|
992
|
-
var cache = {};
|
|
993
|
-
globalThis.__API_CACHE__DO_NOT_USE_OR_YOU_WILL_BE_FIRED = cache;
|
|
994
|
-
function clearApiCacheInternal(api) {
|
|
995
|
-
cache[api] = {};
|
|
996
|
-
}
|
|
997
|
-
function getErrorMessage(error) {
|
|
998
|
-
if (error instanceof Error) {
|
|
999
|
-
if (error.cause) {
|
|
1000
|
-
if (error.message) {
|
|
1001
|
-
return `${error.message} - ${getErrorMessage(error.cause)}`;
|
|
1002
|
-
}
|
|
1003
|
-
return getErrorMessage(error.cause);
|
|
1004
|
-
}
|
|
1005
|
-
return error.message;
|
|
1006
|
-
}
|
|
1007
|
-
return String(error);
|
|
1008
|
-
}
|
|
1009
|
-
async function fetchAndTransformExceptions(input, init) {
|
|
1010
|
-
try {
|
|
1011
|
-
return await fetch(input, init);
|
|
1012
|
-
} catch (e) {
|
|
1013
|
-
return Promise.reject(new InvokeFetchError(getErrorMessage(e), 0, new Headers(), {}));
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
async function performActualHttpFetch(method, completeUrl, body, options, interceptors, authHeaders, credentials) {
|
|
1017
|
-
const headers = {
|
|
1018
|
-
"Content-Type": "application/json",
|
|
1019
|
-
...authHeaders,
|
|
1020
|
-
...options?.headers
|
|
1021
|
-
};
|
|
1022
|
-
const isCrossOrigin = isHostCrossOrigin(options?.hostConfig);
|
|
1023
|
-
let request = {
|
|
1024
|
-
method,
|
|
1025
|
-
credentials,
|
|
1026
|
-
mode: isCrossOrigin ? "cors" : "same-origin",
|
|
1027
|
-
headers,
|
|
1028
|
-
redirect: await isWindows(options?.hostConfig) ? "manual" : "follow",
|
|
1029
|
-
body: body ? JSON.stringify(body) : null
|
|
1030
|
-
// body data type must match "Content-Type" header
|
|
1031
|
-
};
|
|
1032
|
-
let fetchTimeoutId;
|
|
1033
|
-
if (options?.timeoutMs && options.timeoutMs > 0) {
|
|
1034
|
-
const controller = new AbortController();
|
|
1035
|
-
fetchTimeoutId = setTimeout(() => {
|
|
1036
|
-
controller.abort();
|
|
1037
|
-
}, options.timeoutMs);
|
|
1038
|
-
request.signal = controller.signal;
|
|
1039
|
-
}
|
|
1040
|
-
if (interceptors?.request.hasInterceptors()) {
|
|
1041
|
-
request = await interceptors.request.apply(completeUrl, request);
|
|
1042
|
-
}
|
|
1043
|
-
const fetchResponse = await fetchAndTransformExceptions(completeUrl, request);
|
|
1044
|
-
if (fetchTimeoutId) {
|
|
1045
|
-
clearTimeout(fetchTimeoutId);
|
|
1046
|
-
}
|
|
1047
|
-
let invokeFetchResponse = await parseFetchResponse2(fetchResponse, completeUrl);
|
|
1048
|
-
if (interceptors?.response.hasInterceptors()) {
|
|
1049
|
-
invokeFetchResponse = await interceptors.response.apply(invokeFetchResponse);
|
|
1050
|
-
}
|
|
1051
|
-
return invokeFetchResponse;
|
|
1052
|
-
}
|
|
1053
|
-
async function getInvokeFetchUrlParams({
|
|
1054
|
-
method,
|
|
1055
|
-
pathTemplate,
|
|
1056
|
-
pathVariables,
|
|
1057
|
-
query,
|
|
1058
|
-
options
|
|
1059
|
-
}) {
|
|
1060
|
-
const locationUrl = toValidLocationUrl(options?.hostConfig);
|
|
1061
|
-
const {
|
|
1062
|
-
headers: authHeaders,
|
|
1063
|
-
queryParams: authQueryParams,
|
|
1064
|
-
credentials
|
|
1065
|
-
} = await getRestCallAuthParams({
|
|
1066
|
-
hostConfig: options?.hostConfig,
|
|
1067
|
-
method
|
|
1068
|
-
});
|
|
1069
|
-
const url = locationUrl + applyPathVariables(pathTemplate, pathVariables);
|
|
1070
|
-
const queryString = encodeQueryParams({ ...query, ...authQueryParams });
|
|
1071
|
-
const completeUrl = toCompleteUrl(url, queryString);
|
|
1072
|
-
const cacheKey = toCacheKey(url, queryString, options?.headers);
|
|
1073
|
-
return { completeUrl, cacheKey, authHeaders, credentials };
|
|
1074
|
-
}
|
|
1075
|
-
function invokeFetchWithUrl(api, props, interceptors) {
|
|
1076
|
-
return invokeFetchWithUrlAndRetry(
|
|
1077
|
-
api,
|
|
1078
|
-
props,
|
|
1079
|
-
async () => {
|
|
1080
|
-
const { cacheKey, authHeaders, credentials } = await getInvokeFetchUrlParams(props);
|
|
1081
|
-
return invokeFetchWithUrlAndRetry(
|
|
1082
|
-
api,
|
|
1083
|
-
{ ...props, cacheKey, authHeaders, credentials },
|
|
1084
|
-
void 0,
|
|
1085
|
-
// only retry once
|
|
1086
|
-
interceptors
|
|
1087
|
-
);
|
|
1088
|
-
},
|
|
1089
|
-
interceptors
|
|
1090
|
-
);
|
|
1091
|
-
}
|
|
1092
|
-
function invokeFetchWithUrlAndRetry(api, { method, completeUrl, cacheKey, body, options, authHeaders, credentials }, performRetry, interceptors) {
|
|
1093
|
-
if (!cache[api]) {
|
|
1094
|
-
cache[api] = {};
|
|
1095
|
-
}
|
|
1096
|
-
const cacheEntry = isModifyingVerb2(method) ? void 0 : cache[api][cacheKey];
|
|
1097
|
-
if (isModifyingVerb2(method)) {
|
|
1098
|
-
clearRelatedCacheEntries(cache[api], cacheKey);
|
|
1099
|
-
}
|
|
1100
|
-
if (cacheEntry && shouldUseCachedResult(options, cacheEntry, defaultCacheTime)) {
|
|
1101
|
-
cacheEntry.lastHit = /* @__PURE__ */ new Date();
|
|
1102
|
-
cacheEntry.hitCount += 1;
|
|
1103
|
-
cacheEntry.accessedPaths.add(globalThis.location ? globalThis.location.pathname : "node");
|
|
1104
|
-
return cloneResultPromise(cacheEntry.value);
|
|
1105
|
-
}
|
|
1106
|
-
const resultPromiseFromBackend = performActualHttpFetch(
|
|
1107
|
-
method,
|
|
1108
|
-
completeUrl,
|
|
1109
|
-
body,
|
|
1110
|
-
options,
|
|
1111
|
-
interceptors,
|
|
1112
|
-
authHeaders,
|
|
1113
|
-
credentials
|
|
1114
|
-
);
|
|
1115
|
-
const resultAfterAuthenticationCheck = interceptAuthenticationErrors(
|
|
1116
|
-
options?.hostConfig,
|
|
1117
|
-
resultPromiseFromBackend,
|
|
1118
|
-
performRetry
|
|
1119
|
-
);
|
|
1120
|
-
const resultPromiseAfterPagingAddon = addPagingFunctions(
|
|
1121
|
-
api,
|
|
1122
|
-
resultAfterAuthenticationCheck,
|
|
1123
|
-
method,
|
|
1124
|
-
body,
|
|
1125
|
-
options,
|
|
1126
|
-
interceptors,
|
|
1127
|
-
authHeaders,
|
|
1128
|
-
credentials
|
|
1129
|
-
);
|
|
1130
|
-
const resultPromiseAfterCacheClearing = clearCacheOnError(cache[api], cacheKey, resultPromiseAfterPagingAddon);
|
|
1131
|
-
if (shouldPopulateCache(method)) {
|
|
1132
|
-
if (Object.hasOwn && !Object.hasOwn(cache, api) || api === "__proto__") {
|
|
1133
|
-
throw new Error(`Forbidden api name: ${api}`);
|
|
1134
|
-
}
|
|
1135
|
-
cache[api][cacheKey] = {
|
|
1136
|
-
lastPulled: Date.now(),
|
|
1137
|
-
value: resultPromiseAfterCacheClearing,
|
|
1138
|
-
lastHit: null,
|
|
1139
|
-
hitCount: 0,
|
|
1140
|
-
accessedPaths: /* @__PURE__ */ new Set()
|
|
1141
|
-
};
|
|
1142
|
-
}
|
|
1143
|
-
return cloneResultPromise(resultPromiseAfterCacheClearing);
|
|
1144
|
-
}
|
|
1145
|
-
function addPagingFunctions(api, value, method, body, options, interceptors, authHeaders, credentials) {
|
|
1146
|
-
return value.then((resp) => {
|
|
1147
|
-
const dataWithPotentialLinks = resp.data;
|
|
1148
|
-
const prevUrl = dataWithPotentialLinks.links?.prev?.href;
|
|
1149
|
-
const nextUrl = dataWithPotentialLinks.links?.next?.href;
|
|
1150
|
-
if (prevUrl) {
|
|
1151
|
-
resp.prev = (prevOptions) => invokeFetchWithUrl(
|
|
1152
|
-
api,
|
|
1153
|
-
{
|
|
1154
|
-
method,
|
|
1155
|
-
completeUrl: prevUrl,
|
|
1156
|
-
body,
|
|
1157
|
-
options: prevOptions || options,
|
|
1158
|
-
cacheKey: toCacheKey(prevUrl, "", options?.headers),
|
|
1159
|
-
authHeaders,
|
|
1160
|
-
credentials
|
|
1161
|
-
},
|
|
1162
|
-
interceptors
|
|
1163
|
-
);
|
|
1164
|
-
}
|
|
1165
|
-
if (nextUrl) {
|
|
1166
|
-
resp.next = (nextOptions) => invokeFetchWithUrl(
|
|
1167
|
-
api,
|
|
1168
|
-
{
|
|
1169
|
-
method,
|
|
1170
|
-
completeUrl: nextUrl,
|
|
1171
|
-
body,
|
|
1172
|
-
options: nextOptions || options,
|
|
1173
|
-
cacheKey: toCacheKey(nextUrl, "", options?.headers),
|
|
1174
|
-
authHeaders,
|
|
1175
|
-
credentials
|
|
1176
|
-
},
|
|
1177
|
-
interceptors
|
|
1178
|
-
);
|
|
1179
|
-
}
|
|
1180
|
-
return resp;
|
|
1181
|
-
});
|
|
1182
|
-
}
|
|
1183
|
-
function neverResolvingPromise() {
|
|
1184
|
-
return new Promise(() => {
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1187
|
-
async function interceptAuthenticationErrors(hostConfig, resultPromise, performRetry) {
|
|
1188
|
-
try {
|
|
1189
|
-
return await resultPromise;
|
|
1190
|
-
} catch (error) {
|
|
1191
|
-
const err = error;
|
|
1192
|
-
if (err.status === 401 || err.status === 403 || (err.status === 301 || err.status === 302) && await isWindows(hostConfig)) {
|
|
1193
|
-
if (globalThis.loggingOut) {
|
|
1194
|
-
return await neverResolvingPromise();
|
|
1195
|
-
}
|
|
1196
|
-
const { retry, preventDefault } = await handleAuthenticationError({
|
|
1197
|
-
hostConfig,
|
|
1198
|
-
status: err.status,
|
|
1199
|
-
headers: err.headers,
|
|
1200
|
-
errorBody: err.data,
|
|
1201
|
-
canRetry: !!performRetry
|
|
1202
|
-
});
|
|
1203
|
-
if (retry && performRetry) {
|
|
1204
|
-
return await performRetry();
|
|
1205
|
-
}
|
|
1206
|
-
if (preventDefault) {
|
|
1207
|
-
return neverResolvingPromise();
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
throw error;
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
async function parseFetchResponse2(fetchResponse, url) {
|
|
1214
|
-
let resultData;
|
|
1215
|
-
try {
|
|
1216
|
-
resultData = await fetchResponse.text();
|
|
1217
|
-
resultData = JSON.parse(resultData);
|
|
1218
|
-
} catch {
|
|
1219
|
-
}
|
|
1220
|
-
const { status, statusText, headers } = fetchResponse;
|
|
1221
|
-
const errorMsg = `request to '${url}' failed with status ${status} ${statusText}.`;
|
|
1222
|
-
if (status >= 300) {
|
|
1223
|
-
throw new InvokeFetchError(errorMsg, status, headers, resultData);
|
|
1224
|
-
}
|
|
1225
|
-
if (status === 0) {
|
|
1226
|
-
throw new InvokeFetchError(errorMsg, 302, headers, resultData);
|
|
1227
|
-
}
|
|
1228
|
-
const invokeFetchResponse = {
|
|
1229
|
-
status,
|
|
1230
|
-
headers,
|
|
1231
|
-
data: resultData
|
|
1232
|
-
};
|
|
1233
|
-
return invokeFetchResponse;
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
|
-
// src/invoke-fetch/invoke-fetch-error.ts
|
|
1237
|
-
var InvokeFetchError = class extends Error {
|
|
1238
|
-
status;
|
|
1239
|
-
headers;
|
|
1240
|
-
data;
|
|
1241
|
-
constructor(errorMessage, status, headers, data) {
|
|
1242
|
-
super(errorMessage);
|
|
1243
|
-
this.status = status;
|
|
1244
|
-
this.headers = headers;
|
|
1245
|
-
this.data = data;
|
|
1246
|
-
this.stack = cleanStack(this.stack);
|
|
1247
|
-
}
|
|
1248
|
-
};
|
|
1249
|
-
var regex = /^.+\/qmfe-api(?:\.js)?:(\d+)(?::\d+)?$/gim;
|
|
1250
|
-
var isFromQmfeApi = (line) => {
|
|
1251
|
-
const matches = line.match(regex);
|
|
1252
|
-
return Boolean(matches && matches.length > 0);
|
|
1253
|
-
};
|
|
1254
|
-
function cleanStack(stack) {
|
|
1255
|
-
if (!stack) {
|
|
1256
|
-
return stack;
|
|
1257
|
-
}
|
|
1258
|
-
const newStack = [];
|
|
1259
|
-
const lines = stack.split("\n");
|
|
1260
|
-
lines.reverse();
|
|
1261
|
-
for (const line of lines) {
|
|
1262
|
-
if (isFromQmfeApi(line)) {
|
|
1263
|
-
break;
|
|
1264
|
-
}
|
|
1265
|
-
newStack.unshift(line);
|
|
1266
|
-
}
|
|
1267
|
-
return newStack.join("\n");
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
// src/invoke-fetch/invoke-fetch-functions.ts
|
|
1271
|
-
async function invokeFetch(api, props, interceptors) {
|
|
1272
|
-
checkForCrossDomainRequest(props.options?.hostConfig);
|
|
1273
|
-
const { completeUrl, cacheKey, authHeaders, credentials } = await getInvokeFetchUrlParams(props);
|
|
1274
|
-
return invokeFetchWithUrl(
|
|
1275
|
-
api,
|
|
1276
|
-
{ ...props, method: props.method.toUpperCase(), completeUrl, cacheKey, authHeaders, credentials },
|
|
1277
|
-
interceptors
|
|
1278
|
-
);
|
|
1279
|
-
}
|
|
1280
|
-
function clearApiCache(api) {
|
|
1281
|
-
clearApiCacheInternal(api);
|
|
1282
|
-
}
|
|
1283
|
-
async function parseFetchResponse(fetchResponse, url) {
|
|
1284
|
-
let resultData;
|
|
1285
|
-
try {
|
|
1286
|
-
resultData = await fetchResponse.text();
|
|
1287
|
-
resultData = JSON.parse(resultData);
|
|
1288
|
-
} catch {
|
|
1289
|
-
}
|
|
1290
|
-
const { status, statusText, headers } = fetchResponse;
|
|
1291
|
-
const errorMsg = `request to '${url}' failed with status ${status} ${statusText}.`;
|
|
1292
|
-
if (status >= 300) {
|
|
1293
|
-
throw new InvokeFetchError(errorMsg, status, headers, resultData);
|
|
1294
|
-
}
|
|
1295
|
-
if (status === 0) {
|
|
1296
|
-
throw new InvokeFetchError(errorMsg, 302, headers, resultData);
|
|
1297
|
-
}
|
|
1298
|
-
const invokeFetchResponse = {
|
|
1299
|
-
status,
|
|
1300
|
-
headers,
|
|
1301
|
-
data: resultData
|
|
1302
|
-
};
|
|
1303
|
-
return invokeFetchResponse;
|
|
1304
|
-
}
|
|
1305
|
-
|
|
1306
|
-
// src/invoke-fetch/invoke-fetch.ts
|
|
1307
|
-
var invokeFetchExp = {
|
|
1308
|
-
invokeFetch,
|
|
1309
|
-
clearApiCache,
|
|
1310
|
-
parseFetchResponse
|
|
1311
|
-
};
|
|
1312
|
-
var invoke_fetch_default = invokeFetchExp;
|
|
1313
|
-
|
|
1314
|
-
export {
|
|
1315
|
-
getPlatform,
|
|
1316
|
-
InvalidHostConfigError,
|
|
1317
|
-
UnexpectedAuthTypeError,
|
|
1318
|
-
InvalidAuthTypeError,
|
|
1319
|
-
isHostCrossOrigin,
|
|
1320
|
-
isWindows,
|
|
1321
|
-
toValidLocationUrl,
|
|
1322
|
-
toValidEnigmaLocationUrl,
|
|
1323
|
-
getWebSocketAuthParams,
|
|
1324
|
-
getWebResourceAuthParams,
|
|
1325
|
-
handleAuthenticationError,
|
|
1326
|
-
getRestCallAuthParams,
|
|
1327
|
-
registerAuthModule2 as registerAuthModule,
|
|
1328
|
-
setDefaultHostConfig2 as setDefaultHostConfig,
|
|
1329
|
-
checkForCrossDomainRequest,
|
|
1330
|
-
logout,
|
|
1331
|
-
InvokeFetchError,
|
|
1332
|
-
invokeFetch,
|
|
1333
|
-
clearApiCache,
|
|
1334
|
-
parseFetchResponse,
|
|
1335
|
-
invoke_fetch_default,
|
|
1336
|
-
auth_default
|
|
1337
|
-
};
|