@klauswuestefeld/jux-web 2024.3.13 → 2024.4.1

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.
@@ -1,7 +1,7 @@
1
1
  export declare const setBackendUrl: (backendUrl: string) => void;
2
2
  export declare const getBackendUrl: () => string;
3
3
  export declare const handleJuxEvent: (ev: Event) => void;
4
- export declare const backendRequest: (url: string, options: any, onSuccess: any, onError: any, onRedirect?: any, handleUnauthorized?: () => void, retrial?: boolean, retrialNum?: number) => Promise<any>;
4
+ export declare const backendRequest: (url: string, options: any, onSuccess: any, onError: any, onRedirect?: any, requestType?: string, handleUnauthorized?: () => void, retrial?: boolean, retrialNum?: number) => Promise<any>;
5
5
  export declare const backendPost: (endpoint: string, postContent: any, onJsonResponse: (response: any) => any, onHelpMessage: (message: string) => any) => void;
6
6
  export declare const backendGet: (endpoint: string, params: any, onJsonResponse: (response: any) => any, onHelpMessage: (message: string) => any) => void;
7
7
  export declare const requestMagicLink: (data: any, onJsonResponse: (response: any) => any, onUnauthorized: () => void) => void;
@@ -1,11 +1,12 @@
1
1
  export declare class JuxEvent extends Event {
2
+ requestType: string;
2
3
  method: string;
3
4
  endpoint: string;
4
5
  onResult?: (result: any) => any;
5
6
  params: any;
6
7
  onError?: (error: any) => void;
7
8
  onRedirect?: (result: any) => any;
8
- constructor(method: string, endpoint: string, onResult?: (result: any) => any, params?: any, onError?: (error: any) => void, onRedirect?: (result: any) => any);
9
+ constructor(type: string, method: string, endpoint: string, onResult?: (result: any) => any, params?: any, onError?: (error: any) => void, onRedirect?: (result: any) => any);
9
10
  }
10
11
  export declare const query: (element: HTMLElement, endpoint: string, onResult: (result: any) => any, params?: any, onError?: ((error: any) => void) | undefined, onRedirect?: ((result: any) => any) | undefined) => void;
11
12
  export declare const command: (element: HTMLElement, endpoint: string, onResult?: ((result: any) => any) | undefined, params?: any, onError?: ((error: any) => void) | undefined, onRedirect?: ((result: any) => any) | undefined) => void;
package/dist/jux-web.js CHANGED
@@ -159,10 +159,10 @@ var juxWeb = (function (exports) {
159
159
  };
160
160
  // TODO: use jux-events to call commands and queries inside jux-web library
161
161
  const handleJuxEvent = (ev) => {
162
- const { endpoint, onResult, params, onError, onRedirect } = ev;
162
+ const { requestType, endpoint, onResult, params, onError, onRedirect } = ev;
163
163
  const onJsonResponse = (res) => onResult ? onResult(res) : null;
164
164
  const onHelpMessage = (err) => onError ? onError(err) : null;
165
- post(endpoint, params, onJsonResponse, onHelpMessage, onRedirect);
165
+ post(endpoint, params, onJsonResponse, onHelpMessage, onRedirect, requestType);
166
166
  };
167
167
  const applySpinnerStyle = (spinner) => {
168
168
  spinner.style.position = 'fixed';
@@ -193,9 +193,9 @@ var juxWeb = (function (exports) {
193
193
  };
194
194
  let requestRunning = false;
195
195
  const maxRetries = 20;
196
- const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1) => __awaiter$2(void 0, [url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1], void 0, function* (url, options, onSuccess, onError, onRedirect, handleUnauthorized = defaultHandleUnauthorized, retrial = false, retrialNum = 0) {
196
+ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1) => __awaiter$2(void 0, [url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1], void 0, function* (url, options, onSuccess, onError, onRedirect, requestType = 'query', handleUnauthorized = defaultHandleUnauthorized, retrial = false, retrialNum = 0) {
197
197
  if (requestRunning && !retrial) { // only allow one request at a time
198
- setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, handleUnauthorized, false), 300);
198
+ setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false), 300);
199
199
  return;
200
200
  }
201
201
  // @ts-ignore
@@ -207,7 +207,10 @@ var juxWeb = (function (exports) {
207
207
  }
208
208
  let response;
209
209
  requestRunning = true;
210
- const requestInit = Object.assign(Object.assign({}, options), { signal: AbortSignal.timeout(6000) });
210
+ const requestInit = Object.assign({}, options);
211
+ if (requestType === 'query') {
212
+ requestInit.signal = AbortSignal.timeout(15000);
213
+ }
211
214
  if (onRedirect)
212
215
  requestInit.redirect = 'manual'; // Treat redirects manually instead of following them automatically.
213
216
  try {
@@ -215,6 +218,12 @@ var juxWeb = (function (exports) {
215
218
  }
216
219
  catch (err) {
217
220
  // network errors
221
+ if (requestType === 'command') {
222
+ // Do not retry applying command if it fails for the first time.
223
+ onError('There was an error performing your request. Please try again later.');
224
+ requestRunning = false;
225
+ return;
226
+ }
218
227
  if (retrialNum > maxRetries) {
219
228
  removeOverlay();
220
229
  requestRunning = false;
@@ -231,7 +240,7 @@ var juxWeb = (function (exports) {
231
240
  else if (url.includes(getSecondaryBackendUrl())) {
232
241
  url = url.replace(getSecondaryBackendUrl(), getBackendUrl());
233
242
  }
234
- setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, handleUnauthorized, true, retrialNum), 2000);
243
+ setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, true, retrialNum), 2000);
235
244
  };
236
245
  retryRequest();
237
246
  return;
@@ -266,7 +275,7 @@ var juxWeb = (function (exports) {
266
275
  onError(err);
267
276
  }
268
277
  });
269
- const post = (endpoint, body, onSuccess, onError, onRedirect) => {
278
+ const post = (endpoint, body, onSuccess, onError, onRedirect, requestType = "query") => {
270
279
  const options = {
271
280
  method: 'POST',
272
281
  headers: {
@@ -278,7 +287,7 @@ var juxWeb = (function (exports) {
278
287
  // @ts-ignore
279
288
  options.body = JSON.stringify(body);
280
289
  }
281
- return backendRequest(getApiUrl() + endpoint, options, onSuccess, onError, onRedirect);
290
+ return backendRequest(getApiUrl() + endpoint, options, onSuccess, onError, onRedirect, requestType);
282
291
  };
283
292
  const get = (endpoint, onSuccess, onError, onRedirect) => {
284
293
  const options = {
@@ -308,7 +317,7 @@ var juxWeb = (function (exports) {
308
317
  const { email, token } = data;
309
318
  const url = getMagicAuthReqUrl() + encodeURIComponent(email) + '&destination=' + extractTokenFromWindowLocation('destination') + '&token=' + token;
310
319
  const options = {};
311
- backendRequest(url, options, onJsonResponse, console.error, null, onUnauthorized);
320
+ backendRequest(url, options, onJsonResponse, console.error, null, 'query', onUnauthorized);
312
321
  };
313
322
  const openMagicLink = (magicToken, onJsonResponse, onHelpMessage) => {
314
323
  backendRequest(getMagicAuthUrl() + magicToken, {}, onJsonResponse, onHelpMessage);
@@ -14593,8 +14602,9 @@ var juxWeb = (function (exports) {
14593
14602
  };
14594
14603
 
14595
14604
  class JuxEvent extends Event {
14596
- constructor(method, endpoint, onResult, params, onError, onRedirect) {
14605
+ constructor(type, method, endpoint, onResult, params, onError, onRedirect) {
14597
14606
  super('jux-event', { bubbles: true, cancelable: true, composed: true });
14607
+ this.requestType = type;
14598
14608
  this.method = method;
14599
14609
  this.endpoint = endpoint;
14600
14610
  this.onResult = onResult;
@@ -14604,10 +14614,10 @@ var juxWeb = (function (exports) {
14604
14614
  }
14605
14615
  }
14606
14616
  const query = (element, endpoint, onResult, params, onError, onRedirect) => {
14607
- element.dispatchEvent(new JuxEvent('POST', endpoint, onResult, params, onError, onRedirect));
14617
+ element.dispatchEvent(new JuxEvent('query', 'POST', endpoint, onResult, params, onError, onRedirect));
14608
14618
  };
14609
14619
  const command = (element, endpoint, onResult, params, onError, onRedirect) => {
14610
- element.dispatchEvent(new JuxEvent('POST', endpoint, onResult, params, onError, onRedirect));
14620
+ element.dispatchEvent(new JuxEvent('command', 'POST', endpoint, onResult, params, onError, onRedirect));
14611
14621
  };
14612
14622
 
14613
14623
  exports.chosenLanguage = chosenLanguage;
package/dist/main.esm.js CHANGED
@@ -158,10 +158,10 @@ const getMagicAuthReqUrl = () => {
158
158
  };
159
159
  // TODO: use jux-events to call commands and queries inside jux-web library
160
160
  const handleJuxEvent = (ev) => {
161
- const { endpoint, onResult, params, onError, onRedirect } = ev;
161
+ const { requestType, endpoint, onResult, params, onError, onRedirect } = ev;
162
162
  const onJsonResponse = (res) => onResult ? onResult(res) : null;
163
163
  const onHelpMessage = (err) => onError ? onError(err) : null;
164
- post(endpoint, params, onJsonResponse, onHelpMessage, onRedirect);
164
+ post(endpoint, params, onJsonResponse, onHelpMessage, onRedirect, requestType);
165
165
  };
166
166
  const applySpinnerStyle = (spinner) => {
167
167
  spinner.style.position = 'fixed';
@@ -192,9 +192,9 @@ const defaultHandleUnauthorized = () => {
192
192
  };
193
193
  let requestRunning = false;
194
194
  const maxRetries = 20;
195
- const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1) => __awaiter(void 0, [url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1], void 0, function* (url, options, onSuccess, onError, onRedirect, handleUnauthorized = defaultHandleUnauthorized, retrial = false, retrialNum = 0) {
195
+ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1) => __awaiter(void 0, [url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1], void 0, function* (url, options, onSuccess, onError, onRedirect, requestType = 'query', handleUnauthorized = defaultHandleUnauthorized, retrial = false, retrialNum = 0) {
196
196
  if (requestRunning && !retrial) { // only allow one request at a time
197
- setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, handleUnauthorized, false), 300);
197
+ setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false), 300);
198
198
  return;
199
199
  }
200
200
  // @ts-ignore
@@ -206,7 +206,10 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
206
206
  }
207
207
  let response;
208
208
  requestRunning = true;
209
- const requestInit = Object.assign(Object.assign({}, options), { signal: AbortSignal.timeout(6000) });
209
+ const requestInit = Object.assign({}, options);
210
+ if (requestType === 'query') {
211
+ requestInit.signal = AbortSignal.timeout(15000);
212
+ }
210
213
  if (onRedirect)
211
214
  requestInit.redirect = 'manual'; // Treat redirects manually instead of following them automatically.
212
215
  try {
@@ -214,6 +217,12 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
214
217
  }
215
218
  catch (err) {
216
219
  // network errors
220
+ if (requestType === 'command') {
221
+ // Do not retry applying command if it fails for the first time.
222
+ onError('There was an error performing your request. Please try again later.');
223
+ requestRunning = false;
224
+ return;
225
+ }
217
226
  if (retrialNum > maxRetries) {
218
227
  removeOverlay();
219
228
  requestRunning = false;
@@ -230,7 +239,7 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
230
239
  else if (url.includes(getSecondaryBackendUrl())) {
231
240
  url = url.replace(getSecondaryBackendUrl(), getBackendUrl());
232
241
  }
233
- setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, handleUnauthorized, true, retrialNum), 2000);
242
+ setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, true, retrialNum), 2000);
234
243
  };
235
244
  retryRequest();
236
245
  return;
@@ -265,7 +274,7 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
265
274
  onError(err);
266
275
  }
267
276
  });
268
- const post = (endpoint, body, onSuccess, onError, onRedirect) => {
277
+ const post = (endpoint, body, onSuccess, onError, onRedirect, requestType = "query") => {
269
278
  const options = {
270
279
  method: 'POST',
271
280
  headers: {
@@ -277,7 +286,7 @@ const post = (endpoint, body, onSuccess, onError, onRedirect) => {
277
286
  // @ts-ignore
278
287
  options.body = JSON.stringify(body);
279
288
  }
280
- return backendRequest(getApiUrl() + endpoint, options, onSuccess, onError, onRedirect);
289
+ return backendRequest(getApiUrl() + endpoint, options, onSuccess, onError, onRedirect, requestType);
281
290
  };
282
291
  const get = (endpoint, onSuccess, onError, onRedirect) => {
283
292
  const options = {
@@ -307,7 +316,7 @@ const requestMagicLink = (data, onJsonResponse, onUnauthorized) => {
307
316
  const { email, token } = data;
308
317
  const url = getMagicAuthReqUrl() + encodeURIComponent(email) + '&destination=' + extractTokenFromWindowLocation('destination') + '&token=' + token;
309
318
  const options = {};
310
- backendRequest(url, options, onJsonResponse, console.error, null, onUnauthorized);
319
+ backendRequest(url, options, onJsonResponse, console.error, null, 'query', onUnauthorized);
311
320
  };
312
321
  const openMagicLink = (magicToken, onJsonResponse, onHelpMessage) => {
313
322
  backendRequest(getMagicAuthUrl() + magicToken, {}, onJsonResponse, onHelpMessage);
@@ -1273,8 +1282,9 @@ const loginPage = (clientApp, backgroundImg, onUserLogin, loginTypes) => {
1273
1282
  };
1274
1283
 
1275
1284
  class JuxEvent extends Event {
1276
- constructor(method, endpoint, onResult, params, onError, onRedirect) {
1285
+ constructor(type, method, endpoint, onResult, params, onError, onRedirect) {
1277
1286
  super('jux-event', { bubbles: true, cancelable: true, composed: true });
1287
+ this.requestType = type;
1278
1288
  this.method = method;
1279
1289
  this.endpoint = endpoint;
1280
1290
  this.onResult = onResult;
@@ -1284,10 +1294,10 @@ class JuxEvent extends Event {
1284
1294
  }
1285
1295
  }
1286
1296
  const query = (element, endpoint, onResult, params, onError, onRedirect) => {
1287
- element.dispatchEvent(new JuxEvent('POST', endpoint, onResult, params, onError, onRedirect));
1297
+ element.dispatchEvent(new JuxEvent('query', 'POST', endpoint, onResult, params, onError, onRedirect));
1288
1298
  };
1289
1299
  const command = (element, endpoint, onResult, params, onError, onRedirect) => {
1290
- element.dispatchEvent(new JuxEvent('POST', endpoint, onResult, params, onError, onRedirect));
1300
+ element.dispatchEvent(new JuxEvent('command', 'POST', endpoint, onResult, params, onError, onRedirect));
1291
1301
  };
1292
1302
 
1293
1303
  export { chosenLanguage, command, getTranslation, handleJuxEvent, handleMagicLinkRequest, initLanguage, initSession, loginButton, loginPage, magicLinkModal, onMicrosoftSignIn, query, reloadWithLanguageOverride, requestMagicLink };
package/dist/main.js CHANGED
@@ -182,10 +182,10 @@ const getMagicAuthReqUrl = () => {
182
182
  };
183
183
  // TODO: use jux-events to call commands and queries inside jux-web library
184
184
  const handleJuxEvent = (ev) => {
185
- const { endpoint, onResult, params, onError, onRedirect } = ev;
185
+ const { requestType, endpoint, onResult, params, onError, onRedirect } = ev;
186
186
  const onJsonResponse = (res) => onResult ? onResult(res) : null;
187
187
  const onHelpMessage = (err) => onError ? onError(err) : null;
188
- post(endpoint, params, onJsonResponse, onHelpMessage, onRedirect);
188
+ post(endpoint, params, onJsonResponse, onHelpMessage, onRedirect, requestType);
189
189
  };
190
190
  const applySpinnerStyle = (spinner) => {
191
191
  spinner.style.position = 'fixed';
@@ -216,9 +216,9 @@ const defaultHandleUnauthorized = () => {
216
216
  };
217
217
  let requestRunning = false;
218
218
  const maxRetries = 20;
219
- const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1) => __awaiter(void 0, [url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1], void 0, function* (url, options, onSuccess, onError, onRedirect, handleUnauthorized = defaultHandleUnauthorized, retrial = false, retrialNum = 0) {
219
+ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1) => __awaiter(void 0, [url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1], void 0, function* (url, options, onSuccess, onError, onRedirect, requestType = 'query', handleUnauthorized = defaultHandleUnauthorized, retrial = false, retrialNum = 0) {
220
220
  if (requestRunning && !retrial) { // only allow one request at a time
221
- setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, handleUnauthorized, false), 300);
221
+ setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false), 300);
222
222
  return;
223
223
  }
224
224
  // @ts-ignore
@@ -230,7 +230,10 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
230
230
  }
231
231
  let response;
232
232
  requestRunning = true;
233
- const requestInit = Object.assign(Object.assign({}, options), { signal: AbortSignal.timeout(6000) });
233
+ const requestInit = Object.assign({}, options);
234
+ if (requestType === 'query') {
235
+ requestInit.signal = AbortSignal.timeout(15000);
236
+ }
234
237
  if (onRedirect)
235
238
  requestInit.redirect = 'manual'; // Treat redirects manually instead of following them automatically.
236
239
  try {
@@ -238,6 +241,12 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
238
241
  }
239
242
  catch (err) {
240
243
  // network errors
244
+ if (requestType === 'command') {
245
+ // Do not retry applying command if it fails for the first time.
246
+ onError('There was an error performing your request. Please try again later.');
247
+ requestRunning = false;
248
+ return;
249
+ }
241
250
  if (retrialNum > maxRetries) {
242
251
  removeOverlay();
243
252
  requestRunning = false;
@@ -254,7 +263,7 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
254
263
  else if (url.includes(getSecondaryBackendUrl())) {
255
264
  url = url.replace(getSecondaryBackendUrl(), getBackendUrl());
256
265
  }
257
- setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, handleUnauthorized, true, retrialNum), 2000);
266
+ setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, true, retrialNum), 2000);
258
267
  };
259
268
  retryRequest();
260
269
  return;
@@ -289,7 +298,7 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
289
298
  onError(err);
290
299
  }
291
300
  });
292
- const post = (endpoint, body, onSuccess, onError, onRedirect) => {
301
+ const post = (endpoint, body, onSuccess, onError, onRedirect, requestType = "query") => {
293
302
  const options = {
294
303
  method: 'POST',
295
304
  headers: {
@@ -301,7 +310,7 @@ const post = (endpoint, body, onSuccess, onError, onRedirect) => {
301
310
  // @ts-ignore
302
311
  options.body = JSON.stringify(body);
303
312
  }
304
- return backendRequest(getApiUrl() + endpoint, options, onSuccess, onError, onRedirect);
313
+ return backendRequest(getApiUrl() + endpoint, options, onSuccess, onError, onRedirect, requestType);
305
314
  };
306
315
  const get = (endpoint, onSuccess, onError, onRedirect) => {
307
316
  const options = {
@@ -331,7 +340,7 @@ const requestMagicLink = (data, onJsonResponse, onUnauthorized) => {
331
340
  const { email, token } = data;
332
341
  const url = getMagicAuthReqUrl() + encodeURIComponent(email) + '&destination=' + extractTokenFromWindowLocation('destination') + '&token=' + token;
333
342
  const options = {};
334
- backendRequest(url, options, onJsonResponse, console.error, null, onUnauthorized);
343
+ backendRequest(url, options, onJsonResponse, console.error, null, 'query', onUnauthorized);
335
344
  };
336
345
  const openMagicLink = (magicToken, onJsonResponse, onHelpMessage) => {
337
346
  backendRequest(getMagicAuthUrl() + magicToken, {}, onJsonResponse, onHelpMessage);
@@ -1297,8 +1306,9 @@ const loginPage = (clientApp, backgroundImg, onUserLogin, loginTypes) => {
1297
1306
  };
1298
1307
 
1299
1308
  class JuxEvent extends Event {
1300
- constructor(method, endpoint, onResult, params, onError, onRedirect) {
1309
+ constructor(type, method, endpoint, onResult, params, onError, onRedirect) {
1301
1310
  super('jux-event', { bubbles: true, cancelable: true, composed: true });
1311
+ this.requestType = type;
1302
1312
  this.method = method;
1303
1313
  this.endpoint = endpoint;
1304
1314
  this.onResult = onResult;
@@ -1308,10 +1318,10 @@ class JuxEvent extends Event {
1308
1318
  }
1309
1319
  }
1310
1320
  const query = (element, endpoint, onResult, params, onError, onRedirect) => {
1311
- element.dispatchEvent(new JuxEvent('POST', endpoint, onResult, params, onError, onRedirect));
1321
+ element.dispatchEvent(new JuxEvent('query', 'POST', endpoint, onResult, params, onError, onRedirect));
1312
1322
  };
1313
1323
  const command = (element, endpoint, onResult, params, onError, onRedirect) => {
1314
- element.dispatchEvent(new JuxEvent('POST', endpoint, onResult, params, onError, onRedirect));
1324
+ element.dispatchEvent(new JuxEvent('command', 'POST', endpoint, onResult, params, onError, onRedirect));
1315
1325
  };
1316
1326
 
1317
1327
  exports.chosenLanguage = chosenLanguage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@klauswuestefeld/jux-web",
3
- "version": "2024.3.13",
3
+ "version": "2024.4.1",
4
4
  "author": "Jux.House",
5
5
  "license": "Copyrighted",
6
6
  "description": "",