pb-sxp-ui 1.15.20-alpha.4 → 1.15.20

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/dist/index.cjs CHANGED
@@ -736,6 +736,7 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
736
736
  }, [bffDataSource]);
737
737
  // bff API 请求方法
738
738
  const bffFetch = React.useCallback((path, options) => {
739
+ var _a, _b;
739
740
  if (!bffDataSource)
740
741
  return;
741
742
  const url = bffDataSource.url;
@@ -743,19 +744,49 @@ const SxpDataSourceProvider = ({ render, dataSources, utmVal, enableReportEvent
743
744
  const queryString = qs.stringify(options.query);
744
745
  path = `${path}?${queryString}`;
745
746
  }
747
+ let isTikTokChannel = false;
748
+ const params = {};
749
+ const queryString = location.search.slice(1);
750
+ (_a = splitUrlParams(queryString)) === null || _a === void 0 ? void 0 : _a.forEach((val) => {
751
+ const key = val.split('=')[0];
752
+ const value = val.split('=')[1];
753
+ params[key] = value;
754
+ });
755
+ const cl_source = params === null || params === void 0 ? void 0 : params.cl_source;
756
+ if (cl_source &&
757
+ ((_b = [
758
+ '40A-SPRK--DRESS_EYEWEAR-',
759
+ '41A-SPRK--MADRAGUE-',
760
+ '42A-SPRK--MOOD-',
761
+ '43A-SPRK--SUMMER-',
762
+ '44A-SPRK--DRESS_EYEWEAR-',
763
+ '45A-SPRK--MADRAGUE-',
764
+ '46A-SPRK--MOOD-',
765
+ '47A-SPRK--SUMMER-',
766
+ '48A-SPRK--DRESS_EYEWEAR-',
767
+ '49A-SPRK--MADRAGUE-',
768
+ '50A-SPRK--MOOD-',
769
+ '51A-SPRK--SUMMER-'
770
+ ]) === null || _b === void 0 ? void 0 : _b.includes(cl_source))) {
771
+ isTikTokChannel = true;
772
+ }
746
773
  // 事件上报优化
747
774
  // Beacon API 用于发送异步和非阻塞请求到服务器。这类请求不需要响应。
748
- if (options.type === 'beacon' && navigator.sendBeacon) {
749
- return navigator.sendBeacon(`${url}/api/${path}`, new Blob([JSON.stringify(Object.assign(Object.assign(Object.assign({}, options.body), bffDataSource.headers), { 'x-user-id': fakeUserId }))], {
750
- type: 'text/plain'
775
+ if (options.type === 'beacon' && navigator.sendBeacon && !isTikTokChannel) {
776
+ return navigator.sendBeacon(`${url}/api/${path}`, new Blob([
777
+ JSON.stringify({
778
+ body: btoa(encodeURIComponent(JSON.stringify(Object.assign(Object.assign(Object.assign({}, options.body), bffDataSource.headers), { 'x-user-id': fakeUserId }))))
779
+ })
780
+ ], {
781
+ type: 'application/json;charset=UTF-8'
751
782
  }));
752
783
  }
753
784
  return window
754
- .fetch(`${url}/api/${path}`, {
755
- headers: Object.assign({ 'Content-Type': 'application/json', 'x-user-id': fakeUserId }, bffDataSource.headers),
756
- method: options.method,
757
- body: JSON.stringify(options.body)
758
- })
785
+ .fetch(`${url}/api/${path}`, Object.assign({ headers: Object.assign({ 'Content-Type': 'application/json', 'x-user-id': fakeUserId }, bffDataSource.headers), method: options.method, body: isTikTokChannel
786
+ ? JSON.stringify({
787
+ body: btoa(encodeURIComponent(JSON.stringify(options.body)))
788
+ })
789
+ : JSON.stringify(options.body) }, (isTikTokChannel && { keepalive: true })))
759
790
  .then((res) => res.json())
760
791
  .catch((err) => Promise.reject(err));
761
792
  }, [bffDataSource, fakeUserId]);