openxiangda 1.0.37 → 1.0.39

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.
@@ -361,6 +361,99 @@ var withDefaultAppType = (context, params) => {
361
361
  }
362
362
  return params;
363
363
  };
364
+ var AUTH_LOGIN_URL_ENV_KEYS = [
365
+ "loginUrl",
366
+ "authLoginUrl",
367
+ "bathAuthUrl",
368
+ "REACT_APP_VITE_BATH_AUTH_URL",
369
+ "VITE_BATH_AUTH_URL",
370
+ "BATH_AUTH_URL"
371
+ ];
372
+ var normalizeOptionalString = (value) => {
373
+ const text = typeof value === "string" ? value.trim() : "";
374
+ return text || void 0;
375
+ };
376
+ var getCurrentHref = () => {
377
+ if (typeof window === "undefined") {
378
+ return "";
379
+ }
380
+ return window.location?.href || "";
381
+ };
382
+ var resolveAuthLoginUrl = (context, options) => {
383
+ const explicitLoginUrl = normalizeOptionalString(options.loginUrl);
384
+ if (explicitLoginUrl) {
385
+ return explicitLoginUrl;
386
+ }
387
+ for (const key of AUTH_LOGIN_URL_ENV_KEYS) {
388
+ const loginUrl = normalizeOptionalString(context.env?.[key]);
389
+ if (loginUrl) {
390
+ return loginUrl;
391
+ }
392
+ }
393
+ return void 0;
394
+ };
395
+ var buildAuthRedirectUrl = (loginUrl, callbackUrl, callbackParamName) => {
396
+ const paramName = normalizeOptionalString(callbackParamName) || "callback";
397
+ const normalizedCallbackUrl = normalizeOptionalString(callbackUrl);
398
+ if (!normalizedCallbackUrl) {
399
+ return loginUrl;
400
+ }
401
+ const baseHref = getCurrentHref() || "http://localhost/";
402
+ const isAbsoluteUrl = /^[a-z][a-z\d+.-]*:/i.test(loginUrl);
403
+ const isProtocolRelativeUrl = loginUrl.startsWith("//");
404
+ const isRootRelativeUrl = loginUrl.startsWith("/");
405
+ try {
406
+ const url = new URL(loginUrl, baseHref);
407
+ url.searchParams.set(paramName, normalizedCallbackUrl);
408
+ if (isAbsoluteUrl || isProtocolRelativeUrl) {
409
+ return url.toString();
410
+ }
411
+ const path = `${url.pathname}${url.search}${url.hash}`;
412
+ return isRootRelativeUrl ? path : path.replace(/^\//, "");
413
+ } catch {
414
+ const hashIndex = loginUrl.indexOf("#");
415
+ const pathAndQuery = hashIndex >= 0 ? loginUrl.slice(0, hashIndex) : loginUrl;
416
+ const hash = hashIndex >= 0 ? loginUrl.slice(hashIndex) : "";
417
+ const separator = pathAndQuery.includes("?") ? "&" : "?";
418
+ return `${pathAndQuery}${separator}${encodeURIComponent(
419
+ paramName
420
+ )}=${encodeURIComponent(normalizedCallbackUrl)}${hash}`;
421
+ }
422
+ };
423
+ var performRedirect = (url, options) => {
424
+ if (options.redirect) {
425
+ options.redirect(url);
426
+ return;
427
+ }
428
+ if (typeof window === "undefined" || !window.location) {
429
+ return;
430
+ }
431
+ if (options.replace && typeof window.location.replace === "function") {
432
+ window.location.replace(url);
433
+ return;
434
+ }
435
+ window.location.href = url;
436
+ };
437
+ var reloadCurrentPage = () => {
438
+ if (typeof window === "undefined" || !window.location || typeof window.location.reload !== "function") {
439
+ return;
440
+ }
441
+ window.location.reload();
442
+ };
443
+ var redirectAfterLogout = (context, options) => {
444
+ const loginUrl = resolveAuthLoginUrl(context, options);
445
+ const callbackUrl = normalizeOptionalString(options.callbackUrl) || getCurrentHref();
446
+ if (loginUrl) {
447
+ performRedirect(
448
+ buildAuthRedirectUrl(loginUrl, callbackUrl, options.callbackParamName),
449
+ options
450
+ );
451
+ return;
452
+ }
453
+ if (options.fallback !== "none") {
454
+ reloadCurrentPage();
455
+ }
456
+ };
364
457
  var createPageSdk = (context) => {
365
458
  const request = async (options) => {
366
459
  const payload = {
@@ -401,6 +494,26 @@ var createPageSdk = (context) => {
401
494
  throw toSdkError(error, payload);
402
495
  }
403
496
  };
497
+ const logout = () => request({
498
+ path: "/api/auth/logout",
499
+ method: "post"
500
+ });
501
+ const auth = {
502
+ logout,
503
+ logoutAndRedirect: async (options = {}) => {
504
+ try {
505
+ const response = await logout();
506
+ redirectAfterLogout(context, options);
507
+ return response;
508
+ } catch (error) {
509
+ if (options.continueOnLogoutError === false) {
510
+ throw error;
511
+ }
512
+ redirectAfterLogout(context, options);
513
+ return null;
514
+ }
515
+ }
516
+ };
404
517
  const connector = {
405
518
  invoke: (params) => request({
406
519
  path: buildAppPath(
@@ -1101,6 +1214,30 @@ var createPageSdk = (context) => {
1101
1214
  order: Array.isArray(params.order) ? params.order : params.order ? [params.order] : void 0
1102
1215
  }
1103
1216
  });
1217
+ },
1218
+ stats: (code, params = {}) => {
1219
+ const dataViewCode = String(code || "").trim();
1220
+ if (!dataViewCode) {
1221
+ throw new Error("\u6570\u636E\u89C6\u56FE code \u4E0D\u80FD\u4E3A\u7A7A");
1222
+ }
1223
+ return request({
1224
+ path: buildAppPath(
1225
+ context,
1226
+ params.appType,
1227
+ `/v1/data-views/${encodePathSegment(dataViewCode)}/stats.json`
1228
+ ),
1229
+ method: "post",
1230
+ body: {
1231
+ fields: params.fields,
1232
+ filters: serializeSearchExpression(params.filters),
1233
+ having: serializeSearchExpression(params.having),
1234
+ conditionType: params.conditionType,
1235
+ searchKeyWord: params.searchKeyWord,
1236
+ currentPage: params.currentPage,
1237
+ pageSize: params.pageSize,
1238
+ order: Array.isArray(params.order) ? params.order : params.order ? [params.order] : void 0
1239
+ }
1240
+ });
1104
1241
  }
1105
1242
  };
1106
1243
  const notification = {
@@ -1158,6 +1295,7 @@ var createPageSdk = (context) => {
1158
1295
  request,
1159
1296
  download
1160
1297
  },
1298
+ auth,
1161
1299
  connector,
1162
1300
  form,
1163
1301
  user,
@@ -1180,7 +1318,8 @@ var createPageSdk = (context) => {
1180
1318
  runtimeParams.formUuid || descriptor.formUuid || ""
1181
1319
  ).trim();
1182
1320
  switch (descriptor.type) {
1183
- case "dataView.query": {
1321
+ case "dataView.query":
1322
+ case "dataView.stats": {
1184
1323
  const dataViewCode = String(
1185
1324
  runtimeParams.code || runtimeParams.dataViewCode || descriptor.code || descriptor.dataViewCode || descriptor.viewCode || descriptor.key || ""
1186
1325
  ).trim();
@@ -1191,11 +1330,22 @@ var createPageSdk = (context) => {
1191
1330
  filters: mergeSearchExpressions(
1192
1331
  descriptor.defaultFilter,
1193
1332
  runtimeParams.filters
1333
+ ),
1334
+ having: mergeSearchExpressions(
1335
+ descriptor.defaultHaving || descriptor.having,
1336
+ runtimeParams.having
1194
1337
  )
1195
1338
  };
1196
1339
  delete queryParams.code;
1197
1340
  delete queryParams.dataViewCode;
1198
1341
  delete queryParams.viewCode;
1342
+ if (descriptor.type === "dataView.stats") {
1343
+ return dataView.stats(
1344
+ dataViewCode,
1345
+ queryParams
1346
+ );
1347
+ }
1348
+ delete queryParams.having;
1199
1349
  return dataView.query(
1200
1350
  dataViewCode,
1201
1351
  queryParams