@aliyun-obv/api 0.3.42 → 0.3.44

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/api.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { EventSourceMessage } from '@microsoft/fetch-event-source';
1
2
  import { ShowConfig } from '@alifd/next/types/dialog';
2
3
 
3
4
  interface IBaseFetchOptions {
@@ -78,6 +79,34 @@ declare const commonEasyFetch: BaseFetch<IBaseFetchOptions, IResponseData>;
78
79
  */
79
80
  declare const slsEasyFetch: BaseFetch<ISLSFetchOptions, IResponseData>;
80
81
 
82
+ type SSEMethod = 'GET' | 'POST';
83
+ type SSEClientOptions = Omit<RequestInit, 'signal'> & {
84
+ method: SSEMethod;
85
+ onMessage: (data: EventSourceMessage) => void;
86
+ onError?: (err: Error) => void;
87
+ headers: Record<string, string>;
88
+ hideErrorAlert?: boolean;
89
+ onOpen?: (response: Response) => Promise<void>;
90
+ onClose?: () => void;
91
+ };
92
+ interface IsseClient extends Omit<SSEClientOptions, 'headers'> {
93
+ region?: string;
94
+ ingoreSlsRegion?: boolean;
95
+ }
96
+ declare class SSEClient {
97
+ private api;
98
+ private params;
99
+ private options;
100
+ private ctrl;
101
+ private finalUrl;
102
+ constructor(api: string, params: Record<string, any>, options: SSEClientOptions);
103
+ connect(): Promise<void>;
104
+ abort(): void;
105
+ private getRequestBody;
106
+ private buildFinalUrl;
107
+ }
108
+ declare const sseClient: (api: string, params: Record<string, any>, options: IsseClient) => SSEClient;
109
+
81
110
  /**
82
111
  * 全局错误处理函数
83
112
  * @param config
@@ -319,4 +348,4 @@ declare namespace dashbordService {
319
348
  }): Promise<IResponseData>;
320
349
  }
321
350
 
322
- export { IResponseData, commonEasyFetch, dashbordService, diamondService, indexService, metaService, obsEasyFetch, projectService, showAlertDialog, showAlertDialogWhenNeedLogin, slsEasyFetch, workSpaceService };
351
+ export { IResponseData, commonEasyFetch, dashbordService, diamondService, indexService, metaService, obsEasyFetch, projectService, showAlertDialog, showAlertDialogWhenNeedLogin, slsEasyFetch, sseClient, workSpaceService };
package/dist/api.es.js CHANGED
@@ -6,6 +6,7 @@ import { Dialog, Button, Message } from '@alifd/next';
6
6
  import { slsConsoleRuntime } from '@aliyun-obv/utils';
7
7
  import React from 'react';
8
8
  import merge from 'lodash/merge';
9
+ import { fetchEventSource } from '@microsoft/fetch-event-source';
9
10
 
10
11
  function getParams(obj = {}) {
11
12
  return Object.keys(obj).filter((k) => obj[k] || +obj[k] === 0).map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(obj[k])}`).join("&");
@@ -21,24 +22,24 @@ function getPostParam(obj = {}) {
21
22
  }).join("&");
22
23
  }
23
24
 
24
- var __defProp$4 = Object.defineProperty;
25
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
26
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
27
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
28
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
29
- var __spreadValues$4 = (a, b) => {
25
+ var __defProp$5 = Object.defineProperty;
26
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
27
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
28
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
29
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
30
+ var __spreadValues$5 = (a, b) => {
30
31
  for (var prop in b || (b = {}))
31
- if (__hasOwnProp$4.call(b, prop))
32
- __defNormalProp$4(a, prop, b[prop]);
33
- if (__getOwnPropSymbols$4)
34
- for (var prop of __getOwnPropSymbols$4(b)) {
35
- if (__propIsEnum$4.call(b, prop))
36
- __defNormalProp$4(a, prop, b[prop]);
32
+ if (__hasOwnProp$5.call(b, prop))
33
+ __defNormalProp$5(a, prop, b[prop]);
34
+ if (__getOwnPropSymbols$5)
35
+ for (var prop of __getOwnPropSymbols$5(b)) {
36
+ if (__propIsEnum$5.call(b, prop))
37
+ __defNormalProp$5(a, prop, b[prop]);
37
38
  }
38
39
  return a;
39
40
  };
40
- var __publicField = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
41
- var __async$9 = (__this, __arguments, generator) => {
41
+ var __publicField$1 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
42
+ var __async$a = (__this, __arguments, generator) => {
42
43
  return new Promise((resolve, reject) => {
43
44
  var fulfilled = (value) => {
44
45
  try {
@@ -63,8 +64,8 @@ const matchProxyApiReg = /common\/(getApi|postApi|putApi)/;
63
64
  const workspaceReg = /\/region\/(.+?)\/workspace\/(.+?)\//;
64
65
  class BaseFetch {
65
66
  constructor(fetchApi) {
66
- __publicField(this, "fetchApi");
67
- __publicField(this, "defaults", {
67
+ __publicField$1(this, "fetchApi");
68
+ __publicField$1(this, "defaults", {
68
69
  baseURL: "",
69
70
  getDefaultInit: {
70
71
  method: "get",
@@ -102,7 +103,7 @@ class BaseFetch {
102
103
  url = `${this.defaults.baseURL}${url}`;
103
104
  }
104
105
  if ((url.startsWith("http:") || url.startsWith("https:")) && !url.startsWith(window.location.host)) {
105
- newInit = __spreadValues$4({}, Object.assign({}, init, { credentials: "include" }));
106
+ newInit = __spreadValues$5({}, Object.assign({}, init, { credentials: "include" }));
106
107
  }
107
108
  if (this.defaults.beforeRequest) {
108
109
  return this.defaults.beforeRequest(url, params, newInit, options);
@@ -110,7 +111,7 @@ class BaseFetch {
110
111
  return { url, init: newInit };
111
112
  }
112
113
  callFetch(_0, _1) {
113
- return __async$9(this, arguments, function* (api, init, options = {}) {
114
+ return __async$a(this, arguments, function* (api, init, options = {}) {
114
115
  let headers = init == null ? void 0 : init.headers;
115
116
  if (options.headers) {
116
117
  headers = Object.assign({}, init == null ? void 0 : init.headers, options.headers);
@@ -122,7 +123,7 @@ class BaseFetch {
122
123
  });
123
124
  }
124
125
  get(_0) {
125
- return __async$9(this, arguments, function* (api, params = {}, options = {}) {
126
+ return __async$a(this, arguments, function* (api, params = {}, options = {}) {
126
127
  var _a, _b, _c;
127
128
  if (isTest) return Promise.resolve({ res: void 0 });
128
129
  try {
@@ -161,7 +162,7 @@ class BaseFetch {
161
162
  });
162
163
  }
163
164
  _post(_0) {
164
- return __async$9(this, arguments, function* (api, params = {}, options = {}, defaultInit) {
165
+ return __async$a(this, arguments, function* (api, params = {}, options = {}, defaultInit) {
165
166
  var _a;
166
167
  if (isTest) return Promise.resolve({ res: void 0 });
167
168
  try {
@@ -199,19 +200,19 @@ class BaseFetch {
199
200
  });
200
201
  }
201
202
  post(_0) {
202
- return __async$9(this, arguments, function* (api, params = {}, options = {}) {
203
+ return __async$a(this, arguments, function* (api, params = {}, options = {}) {
203
204
  return this._post(api, params, options, this.defaults.postDefaultInit);
204
205
  });
205
206
  }
206
207
  put(_0) {
207
- return __async$9(this, arguments, function* (api, params = {}, options = {}) {
208
+ return __async$a(this, arguments, function* (api, params = {}, options = {}) {
208
209
  return this._post(api, params, options, this.defaults.putDefaultInit);
209
210
  });
210
211
  }
211
212
  }
212
213
 
213
- var _a$1, _b$1, _c;
214
- const isLocal = (_a$1 = window == null ? void 0 : window.ALIYUN_CONSOLE_CONFIG) == null ? void 0 : _a$1.LOCAL;
214
+ var _a$2, _b$1, _c;
215
+ const isLocal = (_a$2 = window == null ? void 0 : window.ALIYUN_CONSOLE_CONFIG) == null ? void 0 : _a$2.LOCAL;
215
216
  const isPre = ((_b$1 = window == null ? void 0 : window.ALIYUN_CONSOLE_CONFIG) == null ? void 0 : _b$1.fEnv) === "pre" || ((_c = window == null ? void 0 : window.ALIYUN_CONSOLE_CONFIG) == null ? void 0 : _c.ENV) === "pre";
216
217
  function is4Service(location2) {
217
218
  return location2.hostname.match(
@@ -386,26 +387,26 @@ function addRUMLog(log) {
386
387
  }
387
388
  }
388
389
 
389
- var __defProp$3 = Object.defineProperty;
390
- var __defProps$3 = Object.defineProperties;
391
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
392
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
393
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
394
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
395
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
396
- var __spreadValues$3 = (a, b) => {
390
+ var __defProp$4 = Object.defineProperty;
391
+ var __defProps$4 = Object.defineProperties;
392
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
393
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
394
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
395
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
396
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
397
+ var __spreadValues$4 = (a, b) => {
397
398
  for (var prop in b || (b = {}))
398
- if (__hasOwnProp$3.call(b, prop))
399
- __defNormalProp$3(a, prop, b[prop]);
400
- if (__getOwnPropSymbols$3)
401
- for (var prop of __getOwnPropSymbols$3(b)) {
402
- if (__propIsEnum$3.call(b, prop))
403
- __defNormalProp$3(a, prop, b[prop]);
399
+ if (__hasOwnProp$4.call(b, prop))
400
+ __defNormalProp$4(a, prop, b[prop]);
401
+ if (__getOwnPropSymbols$4)
402
+ for (var prop of __getOwnPropSymbols$4(b)) {
403
+ if (__propIsEnum$4.call(b, prop))
404
+ __defNormalProp$4(a, prop, b[prop]);
404
405
  }
405
406
  return a;
406
407
  };
407
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
408
- var __async$8 = (__this, __arguments, generator) => {
408
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
409
+ var __async$9 = (__this, __arguments, generator) => {
409
410
  return new Promise((resolve, reject) => {
410
411
  var fulfilled = (value) => {
411
412
  try {
@@ -428,10 +429,10 @@ var __async$8 = (__this, __arguments, generator) => {
428
429
  const commonEasyFetch = new BaseFetch();
429
430
  commonEasyFetch.defaults.postDefaultInit.headers["Content-Type"] = "application/x-www-form-urlencoded";
430
431
  commonEasyFetch.defaults.postDefaultInit.headers["Accept"] = "application/json";
431
- commonEasyFetch.defaults.afterResponse = (response) => __async$8(void 0, null, function* () {
432
+ commonEasyFetch.defaults.afterResponse = (response) => __async$9(void 0, null, function* () {
432
433
  if (response.status >= 200 && response.status < 300) {
433
434
  const data = yield response.json();
434
- return __spreadProps$3(__spreadValues$3({}, data != null ? data : {}), {
435
+ return __spreadProps$4(__spreadValues$4({}, data != null ? data : {}), {
435
436
  response
436
437
  });
437
438
  } else {
@@ -685,26 +686,26 @@ const errorHandler = (request, error, options) => {
685
686
  throw errorMessage;
686
687
  };
687
688
 
688
- var __defProp$2 = Object.defineProperty;
689
- var __defProps$2 = Object.defineProperties;
690
- var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
691
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
692
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
693
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
694
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
695
- var __spreadValues$2 = (a, b) => {
689
+ var __defProp$3 = Object.defineProperty;
690
+ var __defProps$3 = Object.defineProperties;
691
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
692
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
693
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
694
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
695
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
696
+ var __spreadValues$3 = (a, b) => {
696
697
  for (var prop in b || (b = {}))
697
- if (__hasOwnProp$2.call(b, prop))
698
- __defNormalProp$2(a, prop, b[prop]);
699
- if (__getOwnPropSymbols$2)
700
- for (var prop of __getOwnPropSymbols$2(b)) {
701
- if (__propIsEnum$2.call(b, prop))
702
- __defNormalProp$2(a, prop, b[prop]);
698
+ if (__hasOwnProp$3.call(b, prop))
699
+ __defNormalProp$3(a, prop, b[prop]);
700
+ if (__getOwnPropSymbols$3)
701
+ for (var prop of __getOwnPropSymbols$3(b)) {
702
+ if (__propIsEnum$3.call(b, prop))
703
+ __defNormalProp$3(a, prop, b[prop]);
703
704
  }
704
705
  return a;
705
706
  };
706
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
707
- var __async$7 = (__this, __arguments, generator) => {
707
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
708
+ var __async$8 = (__this, __arguments, generator) => {
708
709
  return new Promise((resolve, reject) => {
709
710
  var fulfilled = (value) => {
710
711
  try {
@@ -724,20 +725,20 @@ var __async$7 = (__this, __arguments, generator) => {
724
725
  step((generator = generator.apply(__this, __arguments)).next());
725
726
  });
726
727
  };
727
- var _a, _b;
728
- let slsAccessToken = (_a = window == null ? void 0 : window.ALIYUN_SLS_CONSOLE_CONFIG) == null ? void 0 : _a.slsAccessToken;
728
+ var _a$1, _b;
729
+ let slsAccessToken$1 = (_a$1 = window == null ? void 0 : window.ALIYUN_SLS_CONSOLE_CONFIG) == null ? void 0 : _a$1.slsAccessToken;
729
730
  let slsAccessTokenMode = false;
730
731
  const urlQueryObj = urijs(location.search).escapeQuerySpace(false).query(true);
731
732
  const supportRefreshToken = urlQueryObj.supportRefreshToken === "true" && window.top !== window.self && parent != null;
732
733
  try {
733
734
  if (((_b = window.ALIYUN_CONSOLE_CONFIG) == null ? void 0 : _b.ENV) === "pre") {
734
735
  if (urlQueryObj.slsAccessToken) {
735
- slsAccessToken = urlQueryObj.slsAccessToken;
736
+ slsAccessToken$1 = urlQueryObj.slsAccessToken;
736
737
  }
737
738
  }
738
739
  } catch (error) {
739
740
  }
740
- if (Object.prototype.toString.call(slsAccessToken) === "[object String]" && slsAccessToken.length > 0) {
741
+ if (Object.prototype.toString.call(slsAccessToken$1) === "[object String]" && slsAccessToken$1.length > 0) {
741
742
  slsAccessTokenMode = true;
742
743
  }
743
744
  let tokenRefreshing = false;
@@ -754,7 +755,7 @@ function waitRefreshToken() {
754
755
  var _a2, _b2, _c;
755
756
  try {
756
757
  if (((_a2 = event == null ? void 0 : event.data) == null ? void 0 : _a2.type) === "applyAccessToken" && ((_b2 = event == null ? void 0 : event.data) == null ? void 0 : _b2.ticket) === urlQueryObj.sls_ticket) {
757
- slsAccessToken = (_c = event == null ? void 0 : event.data) == null ? void 0 : _c.accessToken;
758
+ slsAccessToken$1 = (_c = event == null ? void 0 : event.data) == null ? void 0 : _c.accessToken;
758
759
  tokenRefreshing = false;
759
760
  const queue = refreshPromisesQueue;
760
761
  refreshPromisesQueue = [];
@@ -772,14 +773,14 @@ function waitRefreshToken() {
772
773
  });
773
774
  }
774
775
  function _finalFetch(api, fetchOptions, deep = 0) {
775
- return __async$7(this, null, function* () {
776
+ return __async$8(this, null, function* () {
776
777
  const requestApi = api;
777
778
  if (tokenRefreshing) {
778
779
  yield waitRefreshToken();
779
780
  }
780
781
  if (slsAccessTokenMode) {
781
- fetchOptions.headers = __spreadProps$2(__spreadValues$2({}, fetchOptions.headers || {}), {
782
- slsAccessToken
782
+ fetchOptions.headers = __spreadProps$3(__spreadValues$3({}, fetchOptions.headers || {}), {
783
+ slsAccessToken: slsAccessToken$1
783
784
  });
784
785
  }
785
786
  const response = yield fetch(requestApi, fetchOptions);
@@ -801,7 +802,7 @@ function _finalFetch(api, fetchOptions, deep = 0) {
801
802
  });
802
803
  }
803
804
  function finalFetch(api, fetchOptions, options) {
804
- return __async$7(this, null, function* () {
805
+ return __async$8(this, null, function* () {
805
806
  let finalOption = fetchOptions;
806
807
  const parseQuery = urijs(decodeURIComponent(location.search)).escapeQuerySpace(false).query(true);
807
808
  if (parseQuery.slsRegion && options.ingoreSlsRegion) {
@@ -822,26 +823,26 @@ function finalFetch(api, fetchOptions, options) {
822
823
  });
823
824
  }
824
825
 
825
- var __defProp$1 = Object.defineProperty;
826
- var __defProps$1 = Object.defineProperties;
827
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
828
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
829
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
830
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
831
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
832
- var __spreadValues$1 = (a, b) => {
826
+ var __defProp$2 = Object.defineProperty;
827
+ var __defProps$2 = Object.defineProperties;
828
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
829
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
830
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
831
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
832
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
833
+ var __spreadValues$2 = (a, b) => {
833
834
  for (var prop in b || (b = {}))
834
- if (__hasOwnProp$1.call(b, prop))
835
- __defNormalProp$1(a, prop, b[prop]);
836
- if (__getOwnPropSymbols$1)
837
- for (var prop of __getOwnPropSymbols$1(b)) {
838
- if (__propIsEnum$1.call(b, prop))
839
- __defNormalProp$1(a, prop, b[prop]);
835
+ if (__hasOwnProp$2.call(b, prop))
836
+ __defNormalProp$2(a, prop, b[prop]);
837
+ if (__getOwnPropSymbols$2)
838
+ for (var prop of __getOwnPropSymbols$2(b)) {
839
+ if (__propIsEnum$2.call(b, prop))
840
+ __defNormalProp$2(a, prop, b[prop]);
840
841
  }
841
842
  return a;
842
843
  };
843
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
844
- var __async$6 = (__this, __arguments, generator) => {
844
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
845
+ var __async$7 = (__this, __arguments, generator) => {
845
846
  return new Promise((resolve, reject) => {
846
847
  var fulfilled = (value) => {
847
848
  try {
@@ -866,7 +867,7 @@ slsEasyFetch.defaults.postDefaultInit.headers["Content-Type"] = "application/x-w
866
867
  slsEasyFetch.defaults.postDefaultInit.headers["Accept"] = "application/json";
867
868
  slsEasyFetch.defaults.baseURL = getSLSdomain();
868
869
  slsEasyFetch.defaults.errorHandler = errorHandler;
869
- slsEasyFetch.defaults.beforeRequest = (url, params, init, options) => __async$6(void 0, null, function* () {
870
+ slsEasyFetch.defaults.beforeRequest = (url, params, init, options) => __async$7(void 0, null, function* () {
870
871
  var _a;
871
872
  const method = (_a = init.method) == null ? void 0 : _a.toLowerCase();
872
873
  if (method === "post" || method === "put") {
@@ -897,15 +898,15 @@ slsEasyFetch.defaults.beforeRequest = (url, params, init, options) => __async$6(
897
898
  };
898
899
  }
899
900
  });
900
- slsEasyFetch.defaults.afterResponse = (r, options) => __async$6(void 0, null, function* () {
901
+ slsEasyFetch.defaults.afterResponse = (r, options) => __async$7(void 0, null, function* () {
901
902
  const { response, data } = r;
902
- let composedData = typeof data === "string" || typeof data === "number" || Array.isArray(data) ? data : __spreadProps$1(__spreadValues$1({}, data), {
903
+ let composedData = typeof data === "string" || typeof data === "number" || Array.isArray(data) ? data : __spreadProps$2(__spreadValues$2({}, data), {
903
904
  response
904
905
  });
905
906
  let hasError = false;
906
907
  if (response.url.indexOf("/console/logs/getLogs.json") !== -1) {
907
908
  const newData = Object.assign({}, data, { requestid: response.headers.get("x-log-requestid") });
908
- composedData = __spreadProps$1(__spreadValues$1({}, newData), {
909
+ composedData = __spreadProps$2(__spreadValues$2({}, newData), {
909
910
  response
910
911
  });
911
912
  if (newData.code && newData.code.toString() !== "200") {
@@ -933,6 +934,131 @@ obsEasyFetch.defaults.errorHandler = errorHandler;
933
934
  obsEasyFetch.defaults.beforeRequest = slsEasyFetch.defaults.beforeRequest;
934
935
  obsEasyFetch.defaults.afterResponse = slsEasyFetch.defaults.afterResponse;
935
936
 
937
+ var __defProp$1 = Object.defineProperty;
938
+ var __defProps$1 = Object.defineProperties;
939
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
940
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
941
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
942
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
943
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
944
+ var __spreadValues$1 = (a, b) => {
945
+ for (var prop in b || (b = {}))
946
+ if (__hasOwnProp$1.call(b, prop))
947
+ __defNormalProp$1(a, prop, b[prop]);
948
+ if (__getOwnPropSymbols$1)
949
+ for (var prop of __getOwnPropSymbols$1(b)) {
950
+ if (__propIsEnum$1.call(b, prop))
951
+ __defNormalProp$1(a, prop, b[prop]);
952
+ }
953
+ return a;
954
+ };
955
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
956
+ var __publicField = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
957
+ var __async$6 = (__this, __arguments, generator) => {
958
+ return new Promise((resolve, reject) => {
959
+ var fulfilled = (value) => {
960
+ try {
961
+ step(generator.next(value));
962
+ } catch (e) {
963
+ reject(e);
964
+ }
965
+ };
966
+ var rejected = (value) => {
967
+ try {
968
+ step(generator.throw(value));
969
+ } catch (e) {
970
+ reject(e);
971
+ }
972
+ };
973
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
974
+ step((generator = generator.apply(__this, __arguments)).next());
975
+ });
976
+ };
977
+ var _a;
978
+ let slsAccessToken = (_a = window == null ? void 0 : window.ALIYUN_SLS_CONSOLE_CONFIG) == null ? void 0 : _a.slsAccessToken;
979
+ class SSEClient {
980
+ constructor(api, params, options) {
981
+ this.api = api;
982
+ this.params = params;
983
+ this.options = options;
984
+ __publicField(this, "ctrl");
985
+ __publicField(this, "finalUrl");
986
+ this.ctrl = new AbortController();
987
+ this.finalUrl = this.buildFinalUrl();
988
+ }
989
+ connect() {
990
+ return __async$6(this, null, function* () {
991
+ try {
992
+ fetchEventSource(this.finalUrl, {
993
+ method: this.options.method,
994
+ headers: this.options.headers,
995
+ body: this.getRequestBody(),
996
+ signal: this.ctrl.signal,
997
+ credentials: "include",
998
+ onopen: this.options.onOpen,
999
+ onmessage: this.options.onMessage,
1000
+ onerror: (error) => {
1001
+ if (this.options.onError) {
1002
+ this.options.onError(error);
1003
+ }
1004
+ if (!this.options.hideErrorAlert) {
1005
+ errorHandler({ method: this.options.method || "GET", api: this.api, params: "" }, error);
1006
+ }
1007
+ throw error;
1008
+ },
1009
+ onclose: this.options.onClose
1010
+ });
1011
+ } catch (error) {
1012
+ throw error;
1013
+ }
1014
+ });
1015
+ }
1016
+ abort() {
1017
+ this.ctrl.abort();
1018
+ }
1019
+ getRequestBody() {
1020
+ if (this.options.method !== "POST") return void 0;
1021
+ if (this.params instanceof FormData) {
1022
+ return this.params;
1023
+ }
1024
+ return JSON.stringify(this.params);
1025
+ }
1026
+ buildFinalUrl() {
1027
+ const domainUrl = getSLSdomain();
1028
+ const hasDomainUrl = domainUrl && typeof domainUrl === "string" && domainUrl.trim().length > 0;
1029
+ const finalUrl = hasDomainUrl ? `${domainUrl}${this.api}` : this.api;
1030
+ if (this.options.method === "POST") return finalUrl;
1031
+ const params = new URLSearchParams();
1032
+ Object.entries(this.params).forEach(([key, value]) => {
1033
+ if (value !== void 0) {
1034
+ if (typeof value === "object") {
1035
+ params.append(key, JSON.stringify(value));
1036
+ } else {
1037
+ params.append(key, String(value));
1038
+ }
1039
+ }
1040
+ });
1041
+ return `${finalUrl}?${params.toString()}`;
1042
+ }
1043
+ }
1044
+ const sseClient = (api, params, options) => {
1045
+ let headers = {
1046
+ "X-CSRF-TOKEN": getConfig("SEC_TOKEN")
1047
+ };
1048
+ if (!options.ingoreSlsRegion) {
1049
+ const parseQuery = urijs(decodeURIComponent(location.search)).escapeQuerySpace(false).query(true);
1050
+ if (parseQuery.slsRegion) {
1051
+ headers["Sls-Region"] = parseQuery.slsRegion;
1052
+ } else if (options.region && options.region.trim() !== "") {
1053
+ headers["Sls-Region"] = options.region;
1054
+ }
1055
+ }
1056
+ if (slsAccessToken) {
1057
+ headers["slsAccessToken"] = slsAccessToken;
1058
+ }
1059
+ return new SSEClient(api, params, __spreadProps$1(__spreadValues$1({}, options), { headers }));
1060
+ };
1061
+
936
1062
  var __defProp = Object.defineProperty;
937
1063
  var __defProps = Object.defineProperties;
938
1064
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -1497,4 +1623,4 @@ var dashbordService;
1497
1623
  dashbordService2.updateDashboard = updateDashboard;
1498
1624
  })(dashbordService || (dashbordService = {}));
1499
1625
 
1500
- export { commonEasyFetch, dashbordService, diamondService, indexService, metaService, obsEasyFetch, projectService, showAlertDialog, showAlertDialogWhenNeedLogin, slsEasyFetch, workSpaceService };
1626
+ export { commonEasyFetch, dashbordService, diamondService, indexService, metaService, obsEasyFetch, projectService, showAlertDialog, showAlertDialogWhenNeedLogin, slsEasyFetch, sseClient, workSpaceService };
package/package.json CHANGED
@@ -8,12 +8,12 @@
8
8
  "scripts": {},
9
9
  "keywords": [],
10
10
  "dependencies": {
11
- "urijs": "^1.19.1",
12
- "lodash": "^4.17.21",
13
11
  "@alicloud/console-base-error-prompt-proxy": "^1.9.12",
14
12
  "@alifd/next": "^1.27.21",
15
- "styled-components": "^5.2.0"
13
+ "@microsoft/fetch-event-source": "^2.0.1",
14
+ "lodash": "^4.17.21",
15
+ "styled-components": "^5.2.0",
16
+ "urijs": "^1.19.1"
16
17
  },
17
- "devDependencies": {},
18
- "version": "0.3.42"
18
+ "version": "0.3.44"
19
19
  }